简体   繁体   English

颤动中的底部导航栏颜色恢复为黑色

[英]Bottom Navigation bar color in flutter revert to black

when changing the bottom navigation bar color in flutter using these lines of code inside main method:在 main 方法中使用以下代码行更改颤动中的底部导航栏颜色时:

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  systemNavigationBarColor: Colors.white,
  statusBarColor: Colors.transparent,
));

it works fine but the bottom navBar color revert to black after some times when using SilverAppBar inside main page :它工作正常,但在主页使用 SilverAppBar一段时间后,底部导航栏颜色恢复为黑色:

body: CustomScrollView(
    slivers: <Widget>[
      SliverAppBar(
        expandedHeight: 300,
        floating: false,
        pinned: true,
        snap: false,
        backgroundColor: Colors.white,
        flexibleSpace: FlexibleSpaceBar(),
      ),
      SliverList(
        delegate: SliverChildListDelegate(<Widget>[

        ]),
      )
    ],
  ),

when changing the value of expandedHeight: 250 the color of bottom navBar won't change, so the problem is inside expandedHeight value , so why and how to fix that .改变的值时expandedHeight: 250底部导航栏的颜色不会改变,所以这个问题是内部expandedHeight值,那么,为什么,以及如何解决这个问题。

The problem is actually not inside the expandedHeight value, but rather it's the fact that the sliver app bar internally uses an AnnotatedRegion to set the system ui overlay style: https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/app_bar.dart#L599问题其实不是在expandedHeight值里面,而是sliver app bar内部使用AnnotatedRegion来设置系统ui覆盖样式的事实: https : //github.com/flutter/flutter/blob/master/packages/颤振/lib/src/material/app_bar.dart#L599

Since you only set the overlay style once in the main method, the new overlay style exposed by the AnnotatedRegion in the app bar will override the old one.由于您只在 main 方法中设置了一次覆盖样式,因此应用栏中AnnotatedRegion公开的新覆盖样式将覆盖旧的覆盖样式。

So what you can do is to wrap your FlexibleSpaceBar within your SliverAppBar with another AnnotatedRegion , to override the AnnotatedRegion that is already in the app bar:所以你可以做的是用另一个AnnotatedRegion将你的FlexibleSpaceBar包裹在你的SliverAppBar ,以覆盖已经在应用栏中的AnnotatedRegion

SliverAppBar(
  expandedHeight: 300,
  floating: false, 
  pinned: true,
  snap: false,
  backgroundColor: Colors.white,
  flexibleSpace: AnnotatedRegion<SystemUiOverlayStyle>(
    value: SystemUiOverlayStyle(
      systemNavigationBarColor: Colors.white,
      statusBarColor: Colors.transparent,
    ),
    child: FlexibleSpaceBar(),
  ),
),

Just for your info仅供您参考

AnnotatedRegion is another way to change the ui overlay style, you can learn more here: https://stackoverflow.com/a/51013116/6064621 AnnotatedRegion是另一种改变ui覆盖样式的方法,你可以在这里了解更多: https : //stackoverflow.com/a/51013116/6064621

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

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