【问题标题】:Flutter Statusbar color not changing颤振状态栏颜色不变
【发布时间】:2021-04-19 05:15:47
【问题描述】:

在我的应用栏中,我将背景颜色设置为 Colors.white,但状态栏颜色仍然是灰色,而它正在正确选择其他颜色。

我不想更改整个应用的状态栏颜色,所以我没有使用:

SystemChrome.setSystemUIOverlayStyle(
        SystemUiOverlayStyle(statusBarColor: Colors.white)); 

我的代码:

 appBar: PreferredSize(
        preferredSize: Size.fromHeight(0),
        child: AppBar(
          backgroundColor: Colors.white,
          elevation: 0,
          brightness: Brightness.light,
        ),
      ),

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    试试这个:

      SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
          statusBarColor: Colors.transparent, 
          statusBarIconBrightness: Brightness.dark, 
          statusBarBrightness: Brightness.dark); 
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    

    [更新]

    那你在这个页面的时候改bar,dispose的时候改回来:

          List<SystemUiOverlayStyle> uiOverlay = [
            SystemUiOverlayStyle.dark,
            SystemUiOverlayStyle.light,
          ];
          int index = 0;
    
      @override
      void dispose() {
        index = 1;
        setState(() {});
        super.dispose();
      }
          
          @override
          Widget build(BuildContext context) {
            return Scaffold(
                body: AnnotatedRegion<SystemUiOverlayStyle>(
              child: Container(
                height: 200,
                color: uiOverlay[index%2]==SystemUiOverlayStyle.dark?Colors.white:Colors.black,
              ),
              value: uiOverlay[index],
              sized: true,
            )
             );
          }
    

    【讨论】:

    • 这将针对整个应用程序进行更改,我只想针对特定屏幕进行更改
    • 当我在 main.dart 中添加代码时,第一个答案有效。谢谢
    【解决方案2】:

    这个呢:

    AppBar(
      backwardsCompatibility: false,
      systemOverlayStyle: SystemUiOverlayStyle(statusBarColor: Colors.white),
    )
    

    【讨论】:

    • 上面写着The named parameter 'backwardsCompatibility' isn't defined.
    • @ajay131 更新你的颤振版本。或者,尝试删除该参数。
    • 我已经是最新的了,哪个参数?
    猜你喜欢
    • 1970-01-01
    • 2019-10-03
    • 1970-01-01
    • 2021-04-13
    • 2017-03-05
    • 2020-10-23
    • 2020-09-27
    • 2020-10-29
    • 1970-01-01
    相关资源
    最近更新 更多