在Flutter的系统文件system_chrome.dart中,有两段代码用来更改状态栏内容的颜色是黑色(dark)还是白色(light):
亮色(白色)
// 系统状态栏内容使用亮色(即白色)绘制,适用于深色背景的应用: static const SystemUiOverlayStyle light = SystemUiOverlayStyle( systemNavigationBarColor: Color(0xFF000000), systemNavigationBarDividerColor: null, statusBarColor: null, systemNavigationBarIconBrightness: Brightness.light, statusBarIconBrightness: Brightness.light, statusBarBrightness: Brightness.dark, );深色(黑色)
// 系统状态栏内容使用深色(即黑色)绘制,适用于浅色背景的应用: static const SystemUiOverlayStyle dark = SystemUiOverlayStyle( systemNavigationBarColor: Color(0xFF000000), systemNavigationBarDividerColor: null, statusBarColor: null, systemNavigationBarIconBrightness: Brightness.light, statusBarIconBrightness: Brightness.dark, statusBarBrightness: Brightness.light, );如何使用:
1、引入material包和services包
import 'package:flutter/material.dart'; // 必须引入services包,才能使用 SystemChrome import 'package:flutter/services.dart';2、设置白色状态栏
void main() { runApp(MyApp()); //白色 SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light); } class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: '我爱模板网', home: Scaffold( backgroundColor: Colors.blue, body: Container(), ), ); } }3、设置黑色状态栏:
void main() { runApp(MyApp()); //黑色 SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark); } class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: '我爱模板网', home: Scaffold( backgroundColor: Colors.white, body: Container(), ), ); } }
部分素材资源来源网站,本站提供免费下载,如有侵权请联系站长马上删除!