pri*_*oo7 7 user-interface android statusbar ios flutter
如何在没有任何第三方插件的情况下更新状态栏图标的颜色?
在我的主题课程中,我有一个函数,我正在尝试下面的代码,但尚未实现结果:
目前的主题代码:
// 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,
),
);
Run Code Online (Sandbox Code Playgroud)
主题更改代码:
// 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();
}
Run Code Online (Sandbox Code Playgroud)
这不是我想要的,因为我不想要第三方解决方案。
目前我在白色/浅色主题中获得黑色图标,并且在主题更改时在深色/黑色主题中获得黑色图标(应该是白色图标)。休息一切正常。
Hem*_*Raj 13
您可以通过调用setSystemUIOverlayStyle
with required 主题来设置状态栏主题。
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
Run Code Online (Sandbox Code Playgroud)
或者
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
Run Code Online (Sandbox Code Playgroud)
更新:
您可以指定自己的属性,例如,
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.white
));
Run Code Online (Sandbox Code Playgroud)
在此处检查可用属性。
注意:对于light
应用程序的主题,使用dark
叠加层,反之亦然。还要确保你import 'package:flutter/services.dart';
希望有帮助!
注意:
如果集合SystemUiOverlayStyle
没有被其他小部件(如AppBar
.
如果AppBar
使用了,请尝试使用,
appBar: AppBar(
title: const Text('Title text'),
brightness: Brightness.dark,
),
Run Code Online (Sandbox Code Playgroud)
对于默认light
或dark
主题。
不要使用AnnotatedRegion
orAppBar.brightness
因为它们已被弃用,请改用它:
更少的定制:
AppBar(
systemOverlayStyle: SystemUiOverlayStyle.dark, // Both iOS and Android (dark icons)
)
Run Code Online (Sandbox Code Playgroud)
更多定制:
AppBar(
systemOverlayStyle: SystemUiOverlayStyle(
statusBarBrightness: Brightness.light, // For iOS: (dark icons)
statusBarIconBrightness: Brightness.dark, // For Android: (dark icons)
statusBarColor: ...,
),
)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10792 次 |
最近记录: |