在使用flutterfa仿造小红书app的时候,点击发布需要修改状态栏为黑色。
Widget build(BuildContext context) {
return Scaffold(
body: pages[currentIndex],
bottomNavigationBar: CustomBottomAppBar(
onTap: (index) {
if (index == 2) {
Future.delayed(Duration(milliseconds: 100), () {
_showBottomSheet(context);
});
return;
}
setState(() {
currentIndex = index;
});
},
currentIndex: currentIndex,
items: [
BottomAppBarItems(label: "首页"),
BottomAppBarItems(label: "工具"),
BottomAppBarItems(iconCenter: const Icon(Icons.add_box_rounded, size: 35, color: Colors.red,)),
BottomAppBarItems(label: "消息"),
BottomAppBarItems(label: "我"),
],
)
);
}
void _showBottomSheet(BuildContext context) {
showModalBottomSheet(
backgroundColor: Colors.black,
context: context,
isScrollControlled: true,
useSafeArea: true,
barrierColor: Colors.white,
builder: (context) => Public()
).whenComplete(() {
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
statusBarColor: Colors.white,
statusBarIconBrightness: Brightness.dark,
));
});
Publish页面代码
void initState() {
super.initState();
// 设置状态栏颜色为黑色
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
statusBarColor: Colors.black,
statusBarIconBrightness: Brightness.light,
));
_showImage();
_showVideo();
}
上面代码没有问题,后来在调试中发现只有从首页跳转的时候才会出现状态栏不会变成黑色,有时候还会闪烁。
再此地记录下,想要单独页面更改状态栏需要设置SafeArea。在Flutter中,SafeArea会在其内部自动保留一定的空间