1、设置app整体状态栏颜色
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light);
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
深色or浅色,在main函数中设置
2、自定义app主题色
flutter的主题色内置的,如果想自定义,就要自定义MaterialColor
static const int _bluePrimaryValue = 0xfff6ffef; static const MaterialColor themeGreen = MaterialColor( _bluePrimaryValue, <int, Color>{ 50: Color(_bluePrimaryValue), 100: Color(_bluePrimaryValue), 200: Color(_bluePrimaryValue), 300: Color(_bluePrimaryValue), 400: Color(_bluePrimaryValue), 500: Color(_bluePrimaryValue), 600: Color(_bluePrimaryValue), 700: Color(_bluePrimaryValue), 800: Color(_bluePrimaryValue), 900: Color(_bluePrimaryValue), }, );
return MaterialApp( title: 'test', theme: ThemeData( primarySwatch: themeGreen, textSelectionColor: WorkColor.colorHint), onGenerateRoute: router.generateRoute, debugShowCheckedModeBanner: false, initialRoute: 'home', ); }
3、app设置中文
flutter默认语言是英语,一般情况使用不到这个默认语言,但是如果用到系统功能,比如长按粘贴复制,就需要更改语言
return MaterialApp( localizationsDelegates: [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, ChineseCupertinoLocalizations.delegate, ], supportedLocales: [ const Locale('zh', 'CN'), const Locale('en', 'US'), ],
、、、、 );}
4、禁止app的自动旋转:
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
]);
在main函数中设置
基于此方法就可以设置app中在某些页面强制横屏,方法如下:
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeRight,
]);
}
@overridevoid dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
super.dispose();
}
but,此方法在ios上并不适用
找来找去,找到了个插件(pub.dev/packages/or…
感谢大佬