[英]Flutter status bar color with SafeArea in iOS
I am using the following code for coloring the status bar in flutter.我正在使用以下代码为 Flutter 中的状态栏着色。
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(statusBarColor: Colors.blue),
child: MaterialApp(
title: 'My App',
theme: ThemeData(
primarySwatch: Colors.blue),
home: MyHomeScreen(),
navigatorKey: navigatorKey,
),
);
}}
class MyHomeScreen extends StatelessWidget {
const MyHomeScreen({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Header(), // my own custom header
),
);
}
}
With the above code I am getting the desired result in Android but in iOS the status bar is still showing in white color.使用上面的代码,我在 Android 中获得了所需的结果,但在 iOS 中,状态栏仍以白色显示。 I have tried this link but I am not getting the desired solution for iOS.
我已经尝试过这个链接,但我没有得到想要的 iOS 解决方案。
Add the following lines to your code ,将以下行添加到您的代码中,
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(statusBarColor: any Color),
);
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
It'll change the whole app's status bar color :)它会改变整个应用程序的状态栏颜色:)
UPDATE:更新:
you can use this trick to achieve status bar color in Ios您可以使用此技巧在 Ios 中实现状态栏颜色
@override
Widget build(BuildContext context) {
return Container(
color: any color,
child: SafeArea(
child: Scaffold(
body: Header(), // my own custom header
),
),
);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.