dart - Flutter - 如何在 AppBar 不存在时设置状态栏颜色
问题描述
AppBar 不存在时如何设置状态栏颜色。
我已经尝试过了,但没有工作。
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';
接下来,只需将其放入您的 App的构建函数中:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.blue, //or set color with: Color(0xFF0000FF)
));
此外,您可以设置有用的属性,例如:statusBarIconBrightness
,systemNavigationBarColor
或systemNavigationBarDividerColor
如果您更喜欢使用更加颤动/小部件的方式来做同样的事情,请考虑使用AnnotatedRegion<SystemUiOverlayStyle>
小部件。
该value:
属性可以设置为SystemUiOverlayStyle()
包含与上图相同的属性的对象。
有关更多信息,请访问API 文档
推荐阅读
- session - Request.IsAuthenticated 在使用 Microsoft O365 登录的 MVC 中使用 Session 后返回 false
- python - 时间戳之间的差异为天
- c# - 为什么 Grpc.Core NuGet 包这么大?
- excel - 用于定位标题“分支”的宏
- types - 当预期有两种不同的返回类型时,Julia @code_warntype 发出警告
- git - 'git gui' / 'git citool' 是否能够触发 git hooks 预提交脚本?
- machine-learning - 我有大约 2000 个用于时间序列预测的多个位置的数据点。我可以在上面应用 LSTM 模型吗?
- ios - 使用 MapKit 和 SwiftUI、Xcode 12 在默认 iOS 地图上移动视图时如何修复“为不可见的矩形请求样式 Z”的终端输出
- c++ - 我尝试使用placement new,但总是遵守错误
- sql - 从 PostgreSQL 中的一组 id 中选择第一个元素