Flutter SystemChrome 小结

固定App 朝向

 ➥单方向

若需要固定应用为单一方向,仅需设置所需要的方向属性即可;

// 竖直上
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
// 竖直下
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitDown]);
// 水平左
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);
// 水平右
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight]);

多方向

 若需要应用随重力感应变化方向,需设置多个方向属性;

// 竖直方向
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
// 水平方向
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeLeft]);
// 多方向
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeLeft, DeviceOrientation.portraitUp]);

Tips:

  1. portraitDown 属性请注意,多方向时一般不会有效果,系统默认不会颠倒;
  2. 多方向设置时初始方向分两种情况,第一种:当前重力感应方向不在设置多方向列表中,初始方向为列表第一个设置方法;第二种:当前重力感应方向在设置多方向列表中,无论顺序第几位,默认均展示当前重力感应方向(非 portraitDown)

设置顶部状态栏 和 底部系统按键

顶部状态栏 顶部状态栏  时间 电量  运营商等等信息的显示  隐藏

**setEnabledSystemUIOverlays** 是指定在应用程序运行时可见的系统叠加,主要对状态栏的操作,读起来比较拗口,但是看测试用例就很明了;参数分 **top 顶部 / bottom 底部** 两种;

只有顶部状态栏 SystemUiOverlay.top

SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);

  

只有底部状系统按键   SystemUiOverlay.bottom

SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);

两者都有

SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top, SystemUiOverlay.bottom]);

设置状态栏颜色 顶部+底部

setSystemUIOverlayStyle:用来设置状态栏顶部和底部样式,默认有 **light** 和 **dark** 模式,也可以按照需求自定义样式;

 ➥ 底部状态栏颜色  systemNavigationBarColor

该属性仅用于 **Android** 设备且 **SDK >= O** 时,底部状态栏颜色;

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(systemNavigationBarColor: Colors.pink));

 

 ➥ 底部状态栏与主内容分割线颜色 systemNavigationBarDividerColor

该属性仅用于 **Android** 设备且 **SDK >= P** 时,底部状态栏与主内容分割线颜色,效果不是很明显;

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(systemNavigationBarDividerColor: Colors.yellow));

 

 ➥ 底部状态栏图标样式 systemNavigationBarIconBrightness

该属性仅用于 **Android** 设备且 **SDK >= O** 时,底部状态栏图标样式,主要是三大按键颜色

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(systemNavigationBarColor: Colors.pink));

 

  ➥ 顶部状态栏背景颜色  statusBarColor

该属性仅用于 **Android** 设备且 **SDK >= M** 时,顶部状态栏颜色;

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(statusBarColor: Colors.red));

 

  ➥ 顶部状态栏图标颜色  statusBarIconBrightness

该属性仅用于 **Android** 设备且 **SDK >= M** 时,顶部状态栏图标的亮度;但小菜感觉并不明显;

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(statusBarIconBrightness: Brightness.dark));

 

  ➥ 顶部状态栏颜色  SystemUiOverlayStyle;此状态 是有灰色和 亮色 两种

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);

SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);

猜你喜欢

转载自blog.csdn.net/nicepainkiller/article/details/122918220