[英]Flutter: How to change system navigation bar color?
class _MyAppState extends State<MyApp> {
DarkThemeProvider themeProvider = DarkThemeProvider();
@override
void initState() {
getCurrentAppTheme();
super.initState();
}
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => themeProvider,)
],
child: Consumer<DarkThemeProvider>(
builder: (BuildContext context, value, Widget child){
return MaterialApp(
theme: Style.themeData(themeProvider.darkTheme, context),
home: Mainpage(),
);
},
)
);
}
}
This is my code.这是我的代码。 I want to change my
systemNavigationBarColor
when darkmode or lightmode.我想在暗模式或亮模式时更改我的
systemNavigationBarColor
。 How to change the color of systemNavigationBarColor
?如何更改
systemNavigationBarColor
的颜色?
When I use SystemChrome
like this,当我像这样使用
SystemChrome
时,
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.dark,
systemNavigationBarColor: Provider.of<DarkThemeProvider>(context).darkTheme ? Colors.black : Colors.white,
systemNavigationBarIconBrightness: Provider.of<DarkThemeProvider>(context).darkTheme ?Brightness.light : Brightness.dark
)
);
this code is not working.此代码不起作用。
You could wrap your screen in an AnnotatedRegion when navigating to it (eg in your routes map):您可以在导航到 AnnotatedRegion 时将屏幕包装在其中(例如在您的路线图中):
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle.light.copyWith(
systemNavigationBarColor: primaryColor,
),
child: MyApp(),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.