[英]Flutter - Change status bar color whithout AppBar
How to change status bar color whithout AppBar?如何在没有 AppBar 的情况下更改状态栏颜色?
my snippet code:我的代码片段:
@override
Widget build(BuildContext context) {
return Scaffold(
body: AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light,
child: BodyWidget(),
),//
);
}
import 'package:flutter/services.dart';
AppBar(
systemOverlayStyle: const SystemUiOverlayStyle(
statusBarColor: Colors.red,
),
),
Another effective way this can be done:另一种有效的方法可以做到这一点:
class MyWidget extends StatelessWidget {
const MyWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
statusBarColor: Colors.red,
systemNavigationBarColor: Colors.red,
statusBarIconBrightness: Brightness.dark,
systemNavigationBarIconBrightness: Brightness.dark,
),
child: Scaffold(),
);
}
}
this work for me
@override
Widget build(BuildContext context) {
return Scaffold(
body: AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light,
child: BodyWidget(),
),//
);
}
I use one general SafeArea in MaterialApp for all pages.我在 MaterialApp 中为所有页面使用了一个通用的 SafeArea。
MaterialApp(
builder: (context, child) {
return Container(
color: Theme.of(context).colorScheme.primary,
child: SafeArea(
child: child!,
),
);
},// other material-app parameters...
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.