Flutter - AppBar 不存在时如何设置状态栏颜色 [英] Flutter - How to set status bar color when AppBar not present
问题描述
如何在 AppBar 不存在时设置状态栏颜色.
How to set status bar color when AppBar not present.
我试过了,但没有用.
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
return new Scaffold(
body: new Container(
color: UniQueryColors.colorBackground,
child: new ListView.builder(
itemCount: 7,
itemBuilder: (BuildContext context, int index){
if (index == 0){
return addTopInfoSection();
}
},
),
),
);
}
输出如下:
推荐答案
首先导入services
包:
import 'package:flutter/services.dart';
接下来,只需将其放入应用的构建函数:
Next, simply put this in the build function of your App:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.blue, //or set color with: Color(0xFF0000FF)
));
此外,您可以设置有用的属性,例如:statusBarIconBrightness
、systemNavigationBarColor
或 systemNavigationBarDividerColor
Additionally, you can set useful properties like: statusBarIconBrightness
, systemNavigationBarColor
or systemNavigationBarDividerColor
如果您更喜欢 flutter/widget 方式来做同样的事情,请考虑使用 AnnotatedRegion
小部件.
If you prefer a more flutter/widget way of doing the same thing, consider using the AnnotatedRegion<SystemUiOverlayStyle>
widget.
value:
属性可以设置为一个 SystemUiOverlayStyle()
对象,其中包含与上述相同的属性.
The value:
property can be set to a SystemUiOverlayStyle()
object containing the same properties as shown above.
有关更多信息,请转到 API 文档
这篇关于Flutter - AppBar 不存在时如何设置状态栏颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!