I am trying to change the status bar color to white … I found this pub on flutter https://pub.dartlang.org/packages/flutter_statusbarcolor … I tried to use the example code on my dart files (main and others) … but it didn’t work … any idea guys ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Works totally fine in my app
import 'package:flutter_statusbarcolor/flutter_statusbarcolor.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
FlutterStatusbarcolor.setStatusBarColor(Colors.white);
return MaterialApp(
title: app_title,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(title: home_title),
);
}
}
UPD: Another solution
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
statusBarColor: Colors.white
));
回答2:
You can use SystemChrome
class to change Status bar and Navigation bar color.
First import
import 'package:flutter/services.dart';
After this, you need to add following lines (better place to put these lines is in your main()
method)
void main() {
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor: Colors.blue, // navigation bar color
statusBarColor: Colors.pink, // status bar color
));
}
回答3:
What you want is Themes. They're important for a lot more than the AppBar color.
https://flutter.io/cookbook/design/themes/