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

标签 text flutter colors statusbar

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

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

这样的努力:

灯光亮度:
enter image description here

暗亮度:
enter image description here

但是,当我启用模拟器的暗模式时,该方法不起作用。
打开模拟器的“深色外观”:
enter image description here

打开“深色外观”后,状态栏文字的颜色无法通过该方法进行任何更改,只能是白色(亮度模式)。
enter image description here

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

方法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(

但是他们都不行。

希望您的帮助!谢谢你。

最佳答案

首先,转到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)),
...

祝你好运!

P.S.
您不必在这里设置亮度!了:)
Scaffold(
    appBar: AppBar(
    brightness: Brightness.light,  //<--Here!!!
    title: Text(widget.title),
),

关于text - Flutter-如何在黑暗模式下更改状态栏文本的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58325556/

相关文章:

flutter - 如何使用 Flutter 官方库

css - 是否可以在 Chrome 中为 css 颜色提供颜色管理

python - Matplotlib:将背景颜色图与 pandas 列值匹配

java - 如何在不计算 java 文件中的原始单词的情况下查找重复单词?

flutter - 右侧带有 labelText 的 TextField

python - 正则表达式匹配python中方括号中的数字

firebase - 如何在一个流中合并多个流

Git:格式化为正确自动着色 %d

android - 在 Android 中使用默认字体样式

ios - 在 iOS 中更改按钮的文本和禁用按钮