简体   繁体   English

Flutter 状态栏颜色不变

[英]Flutter Statusbar color not changing

In my appbar I am providing the background color as Colors.white but the status bar color is still grey, whereas it is picking other colors correctly.在我的应用栏中,我提供的背景颜色为 Colors.white 但状态栏颜色仍然是灰色,而它正在正确选择其他 colors。

I don't want to change the status bar color for entire app so I am not using:我不想更改整个应用程序的状态栏颜色,所以我不使用:

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

My code:我的代码:

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

在此处输入图像描述

What about this:那这个呢:

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

Try this:尝试这个:

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

[UPDATED] [更新]

What about you change the bar when you are in this page, change back when dispose:当你在这个页面时,你改变栏怎么样,在 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,
        )
         );
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM