Raf*_*san 30 statusbar dart flutter
如何在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();
}
},
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
输出看起来像这样:
Han*_* .T 61
简单地把它放在你的应用程序的构建功能中:
import 'package:flutter/services.dart';
Run Code Online (Sandbox Code Playgroud)
此外,您可以设置有用的变量,如:services,statusBarIconBrightness或systemNavigationBarColor
Jor*_*rdy 24
如果您掠夺了AppBar 的源代码,则可以看到它们使用了AnnotatedRegion小部件。
据我了解,当包装在其中的小部件被状态栏/导航栏覆盖时,此小部件会自动设置状态栏/导航栏颜色。
您可以像这样包装小部件:
import 'package:flutter/services.dart';
...
Widget build(BuildContext context) {
return Scaffold(
body: AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light,
child: ...,
),
);
}
Run Code Online (Sandbox Code Playgroud)
小智 8
正如已经提到的解决方案,我正在以不同的方法实施它。遵循的方法是删除AppBar并使用Container小部件更改状态栏的颜色。
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Test',
home: Scaffold(
primary: true,
appBar: EmptyAppBar(),
body: MyScaffold(),
),
),
);
}
class MyScaffold extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Text(
'Test',
),
);
}
}
class EmptyAppBar extends StatelessWidget implements PreferredSizeWidget {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.black,
);
}
@override
Size get preferredSize => Size(0.0, 0.0);
}
Run Code Online (Sandbox Code Playgroud)
参考:GitHub 问题
小智 7
在搜索 SystemChrome 时,我发现了这个:https ://docs.flutter.io/flutter/services/SystemChrome/setSystemUIOverlayStyle.html
示例代码的正上方是一段关于AppBar.brightness.
您应该能够像这样添加一个 AppBar:
Widget build(BuildContext context) {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
return new Scaffold(
appBar: new AppBar(
title: new Text('Nice title!'),
brightness: Brightness.light,
),
body: new Container(
color: UniQueryColors.colorBackground,
child: new ListView.builder(
itemCount: 7,
itemBuilder: (BuildContext context, int index){
if (index == 0){
return addTopInfoSection();
}
},
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
这里是关于亮度的信息
你应该通过两种方式解决这个问题:
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark.copyWith(
statusBarColor: Colors.black,
));
Run Code Online (Sandbox Code Playgroud)
或者
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(
statusBarColor: Colors.white,
));
Run Code Online (Sandbox Code Playgroud)
Scaffold(
appBar: AppBar(
brightness: Brightness.light,
)
)
Run Code Online (Sandbox Code Playgroud)
或者
Scaffold(
appBar: AppBar(
brightness: Brightness.dark,
)
)
Run Code Online (Sandbox Code Playgroud)
在Android上,在对super.onCreate(savedInstanceState)的调用之后,将以下内容添加到MainActivity.java中的 onCreate :
getWindow()。setStatusBarColor(0x00000000);
或者您可以使用flutter_statusbarcolor插件
changeStatusColor(Color color) async {
try {
await FlutterStatusbarcolor.setStatusBarColor(color);
} on PlatformException catch (e) {
print(e);
}
}
Run Code Online (Sandbox Code Playgroud)
使用
AppBar(
systemOverlayStyle: SystemUiOverlayStyle(statusBarColor: Colors.orange),
)
Run Code Online (Sandbox Code Playgroud)
或者
AppBar(
systemOverlayStyle: SystemUiOverlayStyle(statusBarColor: Colors.orange),
)
Run Code Online (Sandbox Code Playgroud)
小智 5
我尝试了很多方法,但它们没有\xe2\x80\x99 工作。我找到了另一种方法,使用 safeArea ,AnnotatedRegion 和 Scaffold
\n\nAnnotatedRegion(\n // status icon and text color, dark:black light:white\n value: SystemUiOverlayStyle.dark,\n child: Scaffold(\n // statusbar color\n backgroundColor: Colors.white,\n body : SafeArea(****)\n )\n}\nRun Code Online (Sandbox Code Playgroud)\n\n代码实现白色状态栏和黑色文本
\n| 归档时间: |
|
| 查看次数: |
22720 次 |
| 最近记录: |