Flutter中的SystemChrome用来控制应用程序的系统级别行为

SystemChrome 是 Flutter 提供的一个类,用来控制应用程序的系统级别行为,如设置全屏,状态栏等。

  1. 设置状态栏透明
SystemChrome.setSystemUIOverlayStyle(
  SystemUiOverlayStyle(
    statusBarColor: Colors.transparent,
    statusBarIconBrightness: Brightness.dark, // 状态栏图标亮色
  ),
);

通过 setSystemUIOverlayStyle 设置状态栏的透明背景和黑色图标。

  1. 修改状态栏文字颜色为白色
SystemChrome.setSystemUIOverlayStyle(
  SystemUiOverlayStyle.dark.copyWith(
    statusBarIconBrightness: Brightness.light,
  ),
);

通过 setSystemUIOverlayStyle 将状态栏的文字颜色修改为白色。

  1. 隐藏底部导航栏
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.top]);

通过 setEnabledSystemUIOverlays 隐藏底部导航栏,只显示状态栏。

  1. 禁止横屏
SystemChrome.setPreferredOrientations([
  DeviceOrientation.portraitUp,
  DeviceOrientation.portraitDown,
]);

通过 setPreferredOrientations 禁止屏幕横屏,只允许竖屏。

  1. 设置全屏模式
SystemChrome.setEnabledSystemUIOverlays([]);

通过 setEnabledSystemUIOverlays 设置全屏模式,即隐藏状态栏、设置面板和导航栏。

  1. 设置状态栏高亮模式
SystemChrome.setSystemUIOverlayStyle(
  SystemUiOverlayStyle.light,
);

通过 setSystemUIOverlayStyle 将状态栏的图标和文字设置为浅色。


如果你有兴趣,可以关注一下我的综合公众号:biglead

猜你喜欢

转载自blog.csdn.net/zl18603543572/article/details/130517305