8.4 设置系统栏样式
问题描述
系统栏颜色有的时候会变成白色,这样就不能看清楚系统栏信息了。
实现步骤:
第 1 步:theme 样式定义
lib/common/style/theme.dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
   |  class AppTheme {      static ThemeData light = ThemeData(     ...     appBarTheme: const AppBarTheme(       systemOverlayStyle: SystemUiOverlayStyle.dark,      ),   );
       static ThemeData dark = ThemeData(     ...     appBarTheme: const AppBarTheme(       systemOverlayStyle: SystemUiOverlayStyle.light,      ),   ); }
 
  | 
 
样式正好和我们的 app 样式相反,这样才能反显文字。
第 2 步:Android 配置
lib/global.dart
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
   |  static void setSystemUi() {   if (GetPlatform.isMobile) {          SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);                       }
    if (GetPlatform.isAndroid) {                         
           SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(              statusBarColor: Colors.transparent,                            
               systemNavigationBarDividerColor: Colors.transparent,              systemNavigationBarColor: Colors.white,              systemNavigationBarIconBrightness: Brightness.dark,     );     SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);   } }
 
  | 
 
1 2 3 4 5 6 7 8
   | class Global {   static Future<void> init() async {     WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();     FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
           setSystemUi();     ...
  | 
 
具体效果大家可以自己尝试,每次需要冷启动,热更新无效。
提交代码到 git