我已将状态栏颜色设置为透明。但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),
]),
),
),
结果是雕像的颜色看起来是灰色的,脚手架是白色的。那么,如何使它们相同呢?非常感谢。
您希望在对状态栏进行调整的每个Stateful Widget
(基本上是每个屏幕(中使用AnnotatedRegion
。我以前用其他方式做过,但AnnotatedRegion确保当您使用Navigator.pop(上下文(返回此屏幕时,状态栏再次更新其样式。只需使用AnnotatedRegion
包装Scaffold,并将值设置为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),
]),
),
),
);
}
希望这能有所帮助。