【问题标题】:Flutter status bar color with SafeArea in iOS在 iOS 中使用 SafeArea 抖动状态栏颜色
【发布时间】:2021-09-16 04:12:15
【问题描述】:

我正在使用以下代码在颤动中为状态栏着色。

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
  ),
);
}
}

使用上面的代码,我在 Android 中得到了想要的结果,但在 iOS 中,状态栏仍然显示为白色。 我已经尝试过this link,但我没有得到所需的 iOS 解决方案。

【问题讨论】:

    标签: flutter statusbar


    【解决方案1】:

    我也有同样的问题。我找到了this 的解决方案。

    试试那个包。

    【讨论】:

      【解决方案2】:

      将以下行添加到您的代码中,

       SystemChrome.setSystemUIOverlayStyle(
            SystemUiOverlayStyle(statusBarColor: any Color),
          );
          SystemChrome.setPreferredOrientations([
            DeviceOrientation.portraitUp,
            DeviceOrientation.portraitDown,
          ]);
      

      它会改变整个应用的状态栏颜色:)

      更新:

      你可以使用这个技巧在Ios中实现状态栏颜色

      @override
      Widget build(BuildContext context) {
      return Container(
             color: any color,
             child: SafeArea(
             child: Scaffold(
        body: Header(), // my own custom header
           ),
         ),
        );
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-09
        • 1970-01-01
        • 1970-01-01
        • 2020-02-04
        • 1970-01-01
        相关资源
        最近更新 更多