本文介绍了如何更改状态文本栏颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CupertinoNavigationBar将状态栏文本颜色放到Brightness Light中

I'm trying put the status bar text color in Brightness Light, with CupertinoNavigationBar

我已经尝试将带有statusBarColor和亮度的SystemUiOverlayStyle放在主菜单中,但是不起作用状态栏中的文本必须为白色

I already tried put in the main the SystemUiOverlayStyle with statusBarColor and the brightness, but not worksThat text in status bar need be white

void main() {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
    systemNavigationBarColor: Colors.white,
    statusBarColor: Colors.white,
    statusBarBrightness: Brightness.light,
    statusBarIconBrightness: Brightness.light
  ));
  runApp(MyApp());
}

我正在尝试为ios和android创建应用栏,但我想将状态栏文本颜色设置为浅色,我要设置一个条件,即如果是ios,则创建CupertinoNavigationBar(),如果是android,则应放置普通的AppBar (),如果只是具有亮度的AppBar,则可以正常工作,但使用CupertinoNavigationBar(),则不会

I'm trying create the appbar for ios and android, but i want put the status bar text color Light, i put a condition which is if is ios i create the CupertinoNavigationBar() and if is android i put the normal AppBar(), if is just the AppBar with brightness, he works fine, but with CupertinoNavigationBar(), no

推荐答案

更新

现在CupertinoNavigationBar也具有brightness属性.

这不可能.

CupertinoNavigationBar使用方法 _wrapWithBackground() 定义状态栏是亮还是暗,因此永远不会考虑使用SystemChrome.setSystemUIOverlayStyle()进行的设置.

CupertinoNavigationBar uses the method _wrapWithBackground() to define whether the status bar is going to be light or dark, so the setting you made with SystemChrome.setSystemUIOverlayStyle() is never going to be considered.

典型的解决方案是创建自己的扩展CupertinoNavigationBar的导航栏,但这在这种情况下不容易实现,因为CupertinoNavigationBar具有私有的State并调用其他私有的类和方法.

A typical solution would be creating your own navigation bar extending CupertinoNavigationBar, but this is not easy to do in such situation, since CupertinoNavigationBar has a private State and calls other private classes and methods.

实际上,与AppBar相比,CupertinoNavigationBar的设计不佳,它考虑了三个属性来定义其亮度:

In fact, CupertinoNavigationBar is poorly designed if you compare to AppBar, which considers three attributes to define its brightness:

    可以通过构造函数传递的
  1. brightness参数;
  2. ThemeData.AppBarTheme.brightness;
  3. ThemeData.primaryColorBrightness.
  1. brightness argument that can be passed through the constructor;
  2. ThemeData.AppBarTheme.brightness;
  3. ThemeData.primaryColorBrightness.

请注意,有一个属性可以指定Cupertino Widgets的亮度,即CupertinoThemeData.brightness,但在_wrapWithBackground()内部却(通常)不考虑该属性.

Notice that there's an attribute to specify the brightness of Cupertino Widgets, which is CupertinoThemeData.brightness, but it is (oddly) not considered inside _wrapWithBackground().

已经有关于此的问题.您应该等待Flutter团队的回应,但在此之前,您可以使用解决方法.

There's an issue about this already. You should wait for Flutter team response, but until then you can use this workaround.

这篇关于如何更改状态文本栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 13:45