最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Flutter SystemChrome使用方法詳解

 更新時間:2022年12月12日 11:49:47   作者:IAM17  
這篇文章主要為大家介紹了Flutter SystemChrome使用方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

引言

SystemChrome 控制操作系統(tǒng)圖形界面的特定方面以及它如何與應(yīng)用程序交互。

需要注意的是在使用的時候一定要保證先執(zhí)行 WidgetsFlutterBinding.ensureInitialized();

setPreferredOrientations 設(shè)置橫屏或堅屏

一般我們顯示是要強制堅屏,只需要指定 DeviceOrientation.portraitUp 就夠了。

SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);

不需要再加上 DeviceOrientation.portraitDown,因為加上也不會有效果。

SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,DeviceOrientation.portraitDown]);

這樣寫也可以,只有后面的 portraitDown 有點多余,如果可以的話,系統(tǒng)不允許在豎直方向倒過來,所以即使是手機設(shè)置中沒有打開方向鎖定,也不用擔(dān)心會倒過來。

如果想在豎直方向倒過來,可以只指定 portraitDown。這樣畫面就會一直倒置。

SystemChrome.setPreferredOrientations([DeviceOrientation.portraitDown]);

如果想設(shè)置畫面水平一般會同時設(shè)置兩個。當手機反轉(zhuǎn)的時候,畫面也可以隨著反轉(zhuǎn)。(沒有設(shè)置鎖定的情況下)

SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight]);

只有禁用多任務(wù)處理時,此設(shè)置才會在 iPad 上生效。

setEnabledSystemUIMode 設(shè)置全屏顯示

用 manual 的方式可以指定顯下面或下面的 overlay,或都不顯示。

//都不顯示,全屏
 SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,overlays: []);
 //顯示上面
 SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,overlays: [SystemUiOverlay.top]);
 //顯示下面
 SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,overlays: [SystemUiOverlay.bottom]);

setSystemUIOverlayStyle 設(shè)置 overlay 樣式,

overlay 的顯示樣式,比如可以顯示 dark style

  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);

android 有效,ios 可能沒有效果。

如果有的設(shè)置沒生效,可以重新啟動 app 試試

全屏播放視頻

如果要全屏播放視頻可以做如下設(shè)置,橫屏,并去掉 overlays。

 SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,overlays: []);
 SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,DeviceOrientation.landscapeRight]);

setSystemUIChangeCallback

只在 android 有效,SystemUiMode 設(shè)置 SystemUiMode.leanBack 或 SystemUiMode.immersive 或 SystemUiMode.immersiveSticky 的時候, overlays 會隨著與用戶交互消失或出現(xiàn),可以監(jiān)聽 setSystemUIChangeCallback 讓 overlays 自動恢復(fù)原來的狀態(tài)。

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),
  )

以上就是Flutter SystemChrome使用方法詳解的詳細內(nèi)容,更多關(guān)于Flutter SystemChrome使用的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論

陆丰市| 泉州市| 张家港市| 远安县| 福鼎市| 乐山市| 秦皇岛市| 罗田县| 萨嘎县| 鹿邑县| 江川县| 屏东县| 英吉沙县| 化隆| 交口县| 常德市| 西畴县| 广宁县| 宁晋县| 北京市| 桐柏县| 缙云县| 石狮市| 晴隆县| 镇康县| 修武县| 工布江达县| 收藏| 华阴市| 苍山县| 名山县| 门头沟区| 开江县| 万山特区| 衡水市| 法库县| 仲巴县| 柳州市| 铁岭市| 西昌市| 肃北|