我希望在iOS 13深色模式下控制状态栏文字的颜色。我可以通过设置脚手架的AppBar属性“亮度”来更改状态栏颜色。代码如下:
return Scaffold(
appBar: AppBar(
brightness: Brightness.light, //<--Here!!!
title: Text(widget.title),
),
...
这样的努力:
但是,当我启用模拟器的“ 暗模式”时,该方法不起作用。打开模拟器的“深色外观”:
打开“深色外观”后,状态栏文本颜色无法通过该方法进行任何更改,只能是白色(亮度模式)。
我试过那些方法来更改状态栏文本颜色:
方法1:
void main() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
runApp(MyApp());
}
方法2:
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light,
child: Material(
child: Scaffold(
appBar: AppBar(
brightness: Brightness.light,
title: Text(widget.title),
),
body: Center(
但是他们都不行。
希望您的帮助!谢谢。
首先,转到ios / Runner文件夹。接下来打开info.plist并将以下行添加到Dict部分。
<key>UIUserInterfaceStyle</key>
<string>Light</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
下一个。确保在MaterialApp的主题设置中包含以下行:
...
MaterialApp(
themeMode: ThemeMode.light, // Change it as you want
theme: ThemeData(
primaryColor: Colors.white,
primaryColorBrightness: Brightness.light,
brightness: Brightness.light,
primaryColorDark: Colors.black,
canvasColor: Colors.white,
// next line is important!
appBarTheme: AppBarTheme(brightness: Brightness.light)),
darkTheme: ThemeData(
primaryColor: Colors.black,
primaryColorBrightness: Brightness.dark,
primaryColorLight: Colors.black,
brightness: Brightness.dark,
primaryColorDark: Colors.black,
indicatorColor: Colors.white,
canvasColor: Colors.black,
// next line is important!
appBarTheme: AppBarTheme(brightness: Brightness.dark)),
...
祝好运!
PS你不必在这里设置亮度!了:)
Scaffold(
appBar: AppBar(
brightness: Brightness.light, //<--Here!!!
title: Text(widget.title),
),