我已将状态栏颜色设置为透明。但是与Appbar还是不一样。
// on main method
if (Platform.isAndroid) {
SystemUiOverlayStyle systemUiOverlayStyle =
SystemUiOverlayStyle(statusBarColor: Colors.transparent);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
// on a widget build method
Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
brightness: Brightness.light,
centerTitle: true,
backgroundColor: Colors.white,
elevation: 0,
title: Text('发现', style: BMTextStyle.black_56),
),
body: SafeArea(
top: false,
child: TabBarView(controller: _controller, children: <Widget>[
_buildPageContentAccordingIndex(0),
_buildPageContentAccordingIndex(1),
]),
),
),
结果是状态栏颜色显示为灰色,而脚手架为白色。那么如何使它们相同呢?谢谢!
答案 0 :(得分:0)
您要在针对状态栏进行调整的每个AnnotatedRegion
(基本上是每个屏幕)中使用Stateful Widget
。我以前以其他方式执行过此操作,但是当您使用Navigator.pop(context)返回此屏幕时,AnnotatedRegion确保状态栏再次更新其样式。只需用AnnotatedRegion
包装支架,然后将值设置为systemUiOverlayStyle
变量,如下所示:
@override
Widget build(BuildContext context) {
SystemUiOverlayStyle _statusBarStyle = SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
);
return AnnotatedRegion(
value: _statusBarStyle,
child: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
brightness: Brightness.light,
centerTitle: true,
backgroundColor: Colors.white,
elevation: 0,
title: Text('发现', style: BMTextStyle.black_56),
),
body: SafeArea(
top: false,
child: TabBarView(controller: _controller, children: <Widget>[
_buildPageContentAccordingIndex(0),
_buildPageContentAccordingIndex(1),
]),
),
),
);
}
希望这会有所帮助。