【发布时间】:2020-01-19 14:05:23
【问题描述】:
如何在没有任何第三方插件的情况下更新状态栏图标的颜色?
在我的主题类中,我有一个函数,我正在尝试使用下面的代码,但目前尚未取得结果:
目前的主题代码:
// 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();
}
这不是我想要的,因为我不想要第三方解决方案。
Icon's color in status bar (Flutter)
目前我正在获得白色/浅色主题中的黑色图标,以及主题更改时深色/黑色主题中的黑色图标(应该是白色图标)。休息一切正常。
【问题讨论】:
-
这能回答你的问题吗? How to change status bar color in Flutter?
标签: android ios user-interface flutter statusbar