Flutter沉浸式状态栏
1.SystemUiOverlayStyle
dark :状态栏字体黑色
light:状态栏字体白色
2.通过Appbar 设置状态栏的字体颜色
appBar: AppBar(brightness: Brightness.light)
3.设置状态栏的的颜色,与字体的颜色
static setBarStatus(bool isDarkIcon,
{Color color: Colors.transparent}) async {
if (Platform.isAndroid) {
if (isDarkIcon) {
SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
statusBarColor: color, statusBarIconBrightness: Brightness.dark);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
} else {
SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
statusBarColor: color, statusBarIconBrightness: Brightness.light);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
}
}
}
4.自定义toolbar:
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.dark,
child: body,
);
class ToolAppBar extends StatelessWidget implements PreferredSizeWidget {
Widget build(BuildContext context) {
return Container();
}
//通过preferredSize 自已头部 appbar
Size get preferredSize => Size.fromHeight(248+kToolbarHeight);
}
5.Flutter SafeArea
使用SafeArea能很好的解决刘海,不规则屏幕的显示问题。
网友评论