如何在没有 AppBar 的情况下为 StatusBar 设置自定义颜色?
为了自定义 StatusBar 颜色,我使用了以下代码:
appBar: AppBar(
backgroundColor: Colors.teal
)
如果我删除appbar
,我将无法自定义 StatusBar。我怎样才能做到这一点?
如何删除 AppBar 但保留 StatusBar?
最佳答案
将此添加到 main.dart
的主方法文件中的 runApp
方法之后
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: <YOUR STATUS BAR COLOR>));
像这样:
void main(){
runApp(MyApp());
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: <YOUR STATUS BAR COLOR>));
}
如果您使用SafeArea
,那么您需要将其top
属性设置为false
。
关于flutter - Flutter 中删除 AppBar 但保留 StatusBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61878704/