当前位置:   article > 正文

Flutter SystemChrome_methodchannel._invokemethod (package:flutter/src/s

methodchannel._invokemethod (package:flutter/src/services/platform_channel.d

        SystemChrome可以为应用设置一个特定的方向去显示,当应用打开时屏幕水平竖直显示.水平和竖直显示分别有两个方向,要么正向朝下,要么反向朝上.

       手机横向和纵向: 手机竖直放置成为纵向,水平称为横向.在以前开发的日子里,我经常把纵向和横向搞反,有时想想觉得自己也好笑.

DeviceOrientation

portraitUp 纵向(竖直)朝上
如果设备的启动画面显示纵向(竖直),需要设置启动画面属性为portraitUp. 否则设备会在使用的过程中将会顺时针方向90度旋转.
  1. await SystemChrome.setPreferredOrientations([
  2. DeviceOrientation.portraitUp
  3. ]);

报错信息 

在main函数初始化时需要调用

WidgetsFlutterBinding.ensureInitialized();

  1. [VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value
  2. #0 MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:142:86)
  3. #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:148:36)
  4. #2 OptionalMethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:461:18)
  5. #3 SystemChrome.setPreferredOrientations (package:flutter/src/services/system_chrome.dart:242:35)
  6. #4 main (package:loan_app/main.dart:23:16)
  7. #5 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:142:25)
  8. #6 _rootRun (dart:async/zone.dart:1354:13)
  9. #7 _CustomZone.run (dart:async/zone.dart:1258:19)
  10. #8 _runZoned (dart:async/zone.dart:1789:10)
  11. #9 runZonedGuarded (dart:async/zone.dart:1777:12)
  12. #10 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:138:5)
  13. #11 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
  1. void main() async {
  2. WidgetsFlutterBinding.ensureInitialized();
  3. await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
  4. }

 portraitDown 纵向(竖直) 朝下 如果设备启动启动画面显示纵向(竖直) 朝上,然后翻转180度,然后纵向(竖直)朝下,点击视频链接可查看

  1. await SystemChrome.setPreferredOrientations([
  2. DeviceOrientation.portraitDown,
  3. ]);
landscapeLeft 横向(水平)向左
portraitUp 纵向(竖直)朝上顺时针旋转90度后的结果

landscapeRight 横向(水平)向右
portraitUp 纵向(竖直)朝上逆时针旋转90度后的结果

屏幕方向集合中包含portraitUp 纵向(竖直)朝上,那么手机屏幕方向纵向(竖直)朝上

  1. await SystemChrome.setPreferredOrientations([
  2. DeviceOrientation.landscapeRight,
  3. DeviceOrientation.landscapeLeft,
  4. DeviceOrientation.portraitDown,
  5. DeviceOrientation.portraitUp
  6. ]);

屏幕方向集合中不包含portraitUp 纵向(竖直)朝上,那么手机屏幕方向将集合中第一项作为屏幕方向

  1. await SystemChrome.setPreferredOrientations([
  2. DeviceOrientation.landscapeRight,
  3. DeviceOrientation.landscapeLeft,
  4. DeviceOrientation.portraitDown,
  5. ]);

SystemUiOverlay  

top 显示顶部状态栏,隐藏底部导航栏 

await SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);

 bottom 隐藏顶部状态栏,显示底部导航栏 

await SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);

 隐藏状态栏和导航栏 适用于应用启动画面全屏显示

await SystemChrome.setEnabledSystemUIOverlays([]);

SystemUiOverlayStyle 

 statusBarColor

 安卓手机顶部状态栏背景颜色,适用于Android N和更高版本

  1. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  2. statusBarIconBrightness: Brightness.dark, statusBarColor: Colors.green));

statusBarIconBrightness

安卓手机顶部状态栏图标颜色,适用于Android N和更高版本

  1. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  2. statusBarIconBrightness: Brightness.light, statusBarColor: Colors.green));

systemNavigationBarColor
Android手机底部状态栏背景颜色
  1. SystemChrome.setSystemUIOverlayStyle(
  2. SystemUiOverlayStyle(systemNavigationBarColor: Colors.green));

systemNavigationBarDividerColor

Android手机底部导航栏和应用内容中间的横线背景颜色

  1. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  2. systemNavigationBarColor: Colors.green,
  3. systemNavigationBarDividerColor:Colors.red,
  4. systemNavigationBarIconBrightness: Brightness.dark));

systemNavigationBarIconBrightness
Android手机底部导航栏图标亮度

  1. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  2. systemNavigationBarColor: Colors.green,
  3. systemNavigationBarIconBrightness: Brightness.dark));

statusBarBrightness
IOS手机顶部状态栏亮度
  1. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  2. statusBarBrightness:Brightness.dark));

  1. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
  2. statusBarBrightness:Brightness.dark));

 ApplicationSwitcherDescription

适用于Web开发浏览器顶部导航栏文本描述 

  1. @override
  2. Widget build(BuildContext context) {
  3. SystemChrome.setApplicationSwitcherDescription(
  4. ApplicationSwitcherDescription(
  5. label: '关于AppLicaionSwitcher描述', primaryColor: 0xff245679));
  6. return Scaffold(
  7. body: Container(),
  8. );
  9. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/455576
推荐阅读
相关标签
  

闽ICP备14008679号