已解决
flutter单独页面修改状态栏不生效问题
来自网友在路上 178878提问 提问时间:2023-09-26 05:52:43阅读次数: 78
最佳答案 问答题库788位专家为你答疑解惑
在使用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,而Public页面设置了SystemChrome.setSystemUIOverlayStyle来更改状态栏颜色,可能会导致状态栏颜色在页面切换时没有被改变。这可能是由于状态栏颜色更改不会触发重新布局,因为没有内容占据状态栏的区域。
再此地记录下,想要单独页面更改状态栏需要设置SafeArea。在Flutter中,SafeArea会在其内部自动保留一定的空间
查看全文
99%的人还看了
相似问题
猜你感兴趣
版权申明
本文"flutter单独页面修改状态栏不生效问题":http://eshow365.cn/6-13706-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!