状态栏中图标的颜色(抖动)

时间:2019-09-17 12:48:50

标签: flutter dart

我正在使用FLUTTER,状态栏的设计指的是黑色 并且状态栏的图标颜色必须为白色 那么如何在抖动中更改状态栏图标的颜色?

3 个答案:

答案 0 :(得分:2)

将以下代码段添加到您的main.dart中。 setSystemUIOverlayStyle允许更改系统叠加样式(如果有)。这将在您的应用程序中全局完成该工作。

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark));

这将为您带来以下效果(iOS和Android)。试玩SystemUiOverlayStyle中的属性以获取所需的内容。

enter image description here

答案 1 :(得分:1)

要将icon更改为白色,请在build方法中尝试以下操作:

import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';

class MyApp extends StatelessWidget {
 @override
  Widget build(BuildContext context) {
    FlutterStatusbarcolor.setStatusBarColor(Colors.white);
    FlutterStatusbarcolor.setStatusBarWhiteForeground(true);
...
}

如果setStatusBarWhiteForeground方法设置为true,则将文本和图标的颜色更改为白色,否则颜色将为黑色。

更多信息在这里: https://github.com/mchome/flutter_statusbarcolor/blob/master/lib/flutter_statusbarcolor.dart#L29

答案 2 :(得分:0)

lib/main.dart 文件中添加此代码段。

        class App extends StatelessWidget {
          // This widget is the root of your application.
          @override
          Widget build(BuildContext context) {
        
            // This code changes background color and icon color of status bar
            SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
              // statusBarColor is used to set Status bar color in Android devices.
              statusBarColor: Colors.transparent,
        
              // To make Status bar icons color white in Android devices.
              statusBarIconBrightness: Brightness.light,
        
              // statusBarBrightness is used to set Status bar icon color in iOS.
              statusBarBrightness: Brightness.dark,
              // Here light means dark icon color for Status bar.
            ));
        
            // material app widget
            return MaterialApp(
        
              // Status bar color
              theme: ThemeData(
                appBarTheme: AppBarTheme(
                  // Brightness.dark will show white color icon
                  brightness: Brightness.dark,
                ),
              ),
        
              color: Colors.white,
        
              title: 'App',
        
              home: Scaffold(),
            );
          }
        }
        

这个link也会对您有所帮助。