如何在没有任何第三方插件的情况下更新状态栏图标的颜色?
在我的主题类中,我有一个函数,在其中我正在尝试以下代码,但迄今为止还没有实现结果:
当前主题代码:
// custom light theme for app
static final customLightTheme = ThemeData.light().copyWith(
brightness: Brightness.light,
primaryColor: notWhite,
accentColor: Colors.amberAccent,
scaffoldBackgroundColor: notWhite,
primaryTextTheme: TextTheme(
title: TextStyle(
color: Colors.black
),
),
appBarTheme: AppBarTheme(
iconTheme: IconThemeData(color: Colors.black),
elevation: 0.0,
)
);
// custom dark theme for app
static final customDarkTheme = ThemeData.dark().copyWith(
brightness: Brightness.dark,
primaryColor: Colors.black,
accentColor: Colors.orange,
scaffoldBackgroundColor: Colors.black87,
primaryTextTheme: TextTheme(
title: TextStyle(
color: Colors.white
),
),
appBarTheme: AppBarTheme(
iconTheme: IconThemeData(color: Colors.white),
elevation: 0.0,
),
);
主题切换器代码:
// set theme for the app
setTheme(ThemeData theme) {
_themeData = theme;
if(_themeData == ThemeChanger.customLightTheme){
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.white,
systemNavigationBarColor: Colors.white,
systemNavigationBarDividerColor: Colors.black,
systemNavigationBarIconBrightness: Brightness.dark,
),
);
} else {
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(
statusBarColor: Colors.blue,
systemNavigationBarColor: Colors.blue,
systemNavigationBarDividerColor: Colors.red,
systemNavigationBarIconBrightness: Brightness.light,
),
);
}
notifyListeners();
}
这不是我想要的,因为我不想要第三方解决方案。
目前在主题更改时,我得到的是白色/浅色主题下的黑色图标,以及黑色/黑色主题下的黑色图标(应该是白色图标)。其他都正常工作。