温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - Flutter-How to change the Statusbar text color in Dark Mode?
colors flutter statusbar text

其他 - Flutter-如何在黑暗模式下更改状态栏文本的颜色?

发布于 2020-04-10 23:26:58

我希望在iOS 13深色模式下控制状态栏文字的颜色。我可以通过设置脚手架的AppBar属性“亮度”来更改状态栏颜色。代码如下:

return Scaffold(
      appBar: AppBar(
        brightness: Brightness.light,  //<--Here!!!
        title: Text(widget.title),
      ),
...

这样的努力:

灯光亮度: 在此处输入图片说明

暗亮度: 在此处输入图片说明

但是,当我启用模拟器的“ 暗模式”时,该方法不起作用。打开模拟器的“深色外观”: 在此处输入图片说明

打开“深色外观”后,状态栏文本颜色无法通过该方法进行任何更改,只能是白色(亮度模式)。 在此处输入图片说明

我试过那些方法来更改状态栏文本颜色:

方法1:

void main() {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]);
  runApp(MyApp());
}

方法2:

return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle.light,
      child: Material(
        child: Scaffold(
          appBar: AppBar(
            brightness: Brightness.light,
            title: Text(widget.title),
          ),
          body: Center(

但是他们都不行。

希望您的帮助!谢谢。

查看更多

提问者
Alexweng
被浏览
118
Dmitry_Kovalov 2020-02-07 23:56

首先,转到ios / Runner文件夹。接下来打开info.plist并将以下行添加到Dict部分。

<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>

下一个。确保在MaterialApp的主题设置中包含以下行:

...
MaterialApp(
    themeMode: ThemeMode.light, // Change it as you want
    theme: ThemeData(
        primaryColor: Colors.white,
        primaryColorBrightness: Brightness.light,
        brightness: Brightness.light,
        primaryColorDark: Colors.black,
        canvasColor: Colors.white,
        // next line is important!
        appBarTheme: AppBarTheme(brightness: Brightness.light)),
    darkTheme: ThemeData(
        primaryColor: Colors.black,
        primaryColorBrightness: Brightness.dark,
        primaryColorLight: Colors.black,
        brightness: Brightness.dark,
        primaryColorDark: Colors.black,      
        indicatorColor: Colors.white,
        canvasColor: Colors.black,
        // next line is important!
        appBarTheme: AppBarTheme(brightness: Brightness.dark)),
...

祝好运!

PS你不必在这里设置亮度!了:)

Scaffold(
    appBar: AppBar(
    brightness: Brightness.light,  //<--Here!!!
    title: Text(widget.title),
),