【问题标题】:Flutter: Change Statusbar Text Color not working properlyFlutter:更改状态栏文本颜色无法正常工作
【发布时间】:2021-04-02 10:57:32
【问题描述】:

Stackoverflow 上提到的几乎所有 Q/A 都与同一主题相关,但没有得到适当的解决方案。

主要问题:我的应用具有原色 蓝色,我想将 状态栏文本颜色设置为白色。

我尝试过的:

  • 使用SystemChrome:(使用下面的代码,只是在第一屏改变状态栏文字的颜色,其他屏幕都是蓝黑组合背景/前景。)

    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
        statusBarColor: MaterialColor(0xFF084775, color), // status bar color
        statusBarBrightness: Brightness.light,//status bar brightness
        statusBarIconBrightness:Brightness.light , //status barIcon Brightness
    ));
    

截图:

启动画面:

仪表板屏幕:


  • 使用 ThemeData :(此方法的结果与上面的屏幕截图相同)。

     theme: ThemeData(
                brightness: Brightness.light, // ADDED THIS LINE..
                primarySwatch: MaterialColor(0xFF084775, color),
                accentColor: Color(0xffe46b10),
                unselectedWidgetColor: Colors.grey,
                fontFamily: 'SourceSansPro',
              ),
    

我也检查了 github issue link,但没有为我工作。

我只需要将状态栏文本颜色更改为白色。有什么帮助吗?

【问题讨论】:

  • 您应该尝试在 Appbar 中添加亮度参数,这可能会起作用。
  • 对于哪个appBar,我有25个屏幕,所有屏幕都有AppBar
  • 您还应该定义 appBar 主题。 :)

标签: flutter statusbar flutter-theme flutter-design


【解决方案1】:

申请所有appBar使用

 return MaterialApp(
                theme: ThemeData(
                  appBarTheme: Theme.of(context).appBarTheme.copyWith(brightness: Brightness.dark),
                ),
                debugShowCheckedModeBanner: false,
                // home: InvoiceList(),
                home: widget());

我希望它会起作用。

谢谢。

【讨论】:

  • 非常感谢:) 它运行良好。
【解决方案2】:

从 Flutter 2 开始

return MaterialApp(
        theme: ThemeData(
            appBarTheme: Theme.of(context)
                .appBarTheme
                .copyWith(systemOverlayStyle: SystemUiOverlayStyle.light)),
        debugShowCheckedModeBanner: false,
        home: widget());

【讨论】:

    猜你喜欢
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    • 2020-02-04
    • 2017-08-18
    • 2019-10-27
    相关资源
    最近更新 更多