網站首頁 編程語言 正文
引言
SystemChrome 控制操作系統圖形界面的特定方面以及它如何與應用程序交互。
需要注意的是在使用的時候一定要保證先執行 WidgetsFlutterBinding.ensureInitialized();
setPreferredOrientations 設置橫屏或堅屏
一般我們顯示是要強制堅屏,只需要指定 DeviceOrientation.portraitUp 就夠了。
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
不需要再加上 DeviceOrientation.portraitDown,因為加上也不會有效果。
SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp,DeviceOrientation.portraitDown]);
這樣寫也可以,只有后面的 portraitDown 有點多余,如果可以的話,系統不允許在豎直方向倒過來,所以即使是手機設置中沒有打開方向鎖定,也不用擔心會倒過來。
如果想在豎直方向倒過來,可以只指定 portraitDown。這樣畫面就會一直倒置。
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitDown]);
如果想設置畫面水平一般會同時設置兩個。當手機反轉的時候,畫面也可以隨著反轉。(沒有設置鎖定的情況下)
SystemChrome.setPreferredOrientations([ DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight]);
只有禁用多任務處理時,此設置才會在 iPad 上生效。
setEnabledSystemUIMode 設置全屏顯示
用 manual 的方式可以指定顯下面或下面的 overlay,或都不顯示。
//都不顯示,全屏 SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,overlays: []); //顯示上面 SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,overlays: [SystemUiOverlay.top]); //顯示下面 SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,overlays: [SystemUiOverlay.bottom]);
setSystemUIOverlayStyle 設置 overlay 樣式,
overlay 的顯示樣式,比如可以顯示 dark style
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
android 有效,ios 可能沒有效果。
如果有的設置沒生效,可以重新啟動 app 試試
全屏播放視頻
如果要全屏播放視頻可以做如下設置,橫屏,并去掉 overlays。
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,overlays: []); SystemChrome.setPreferredOrientations([ DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight]);
setSystemUIChangeCallback
只在 android 有效,SystemUiMode 設置 SystemUiMode.leanBack?或?SystemUiMode.immersive?或?SystemUiMode.immersiveSticky 的時候, overlays 會隨著與用戶交互消失或出現,可以監聽 setSystemUIChangeCallback 讓 overlays 自動恢復原來的狀態。
WidgetsFlutterBinding.ensureInitialized(); SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive); SystemChrome.setSystemUIChangeCallback((systemOverlaysAreVisible) async { await Future.delayed(const Duration(seconds: 1)); SystemChrome.restoreSystemUIOverlays(); });
AnnotatedRegion
如果想控制 status bar 的樣式還可以用 AnnotatedRegion,需要注意的是,使用 AnnotatedRegion 就不要使用 AppBar了,否則會被 AppBar了 覆蓋。
AnnotatedRegion( child: Text('IAM17'), value: SystemUiOverlayStyle( statusBarColor: Colors.green, statusBarIconBrightness: Brightness.light, //底部navigationBar背景顏色 systemNavigationBarColor: Colors.white), )
原文鏈接:https://juejin.cn/post/7176043208265662523
相關推薦
- 2022-10-14 VSCode連接實驗室服務器Xshell,Xftp向服務器傳輸文件的方法(win10)_Linux
- 2022-08-29 Python基礎語法之變量與數據類型詳解_python
- 2022-05-10 二叉樹的遞歸和非遞歸遍歷
- 2021-12-28 Android中實現視差滾動示例介紹_Android
- 2023-11-16 當pytorch找不到 CUDA 時,如何修復錯誤:版本 libcublasLt.so.11 未在帶
- 2022-07-22 Android 舊項目打包 api-versions.xml Stream closed
- 2023-04-02 使用Pytorch如何完成多分類問題_python
- 2022-04-19 Python的閉包和裝飾器你真的了解嗎_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支