方法一
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.bottom]); //隐藏状态栏 上方黑边 SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.top]); //隐藏导航栏 SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); // 隐藏状态栏和导航栏 上方黑板SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle( //设置状态栏透明 statusBarColor: Colors.transparent, ));
方法二(状态栏设置透明)
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter App', theme: ThemeData( primarySwatch: Colors.blue, ), home: Scaffold( appBar: AppBar( backgroundColor: Colors.transparent, // 设置AppBar为透明 elevation: 0, // 去除AppBar的阴影 ), body: Container( // 这里是页面内容 ), ), ); } }
展示如何通过点击屏幕来进入/退出全屏模式,并且在全屏模式下通过滑动屏幕来退出全屏
import 'dart:async'; // 导入使用Timer需要的库 import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; // 导入使用SystemChrome需要的库 void main() { runApp(MyApp()); // 运行应用程序 } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', // 设置应用程序的标题 home: Scaffold( body: MyHomePage(), // 设置主页面为 MyHomePage 组件 ), ); } } class MyHomePage extends StatefulWidget { MyHomePage({Key? key}) : super(key: key); @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { bool _isFullScreen = false; // 判断是否全屏 Timer? _timer; // 定时器 @override void initState() { super.initState(); // 初始化定时器,在每3秒钟检查一次是否需要退出全屏模式 _timer = Timer.periodic(Duration(seconds: 3), (timer) { if (_isFullScreen) { setState(() { SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.top]); _isFullScreen = false; }); } }); } @override Widget build(BuildContext context) { return GestureDetector( onTap: () { if (_isFullScreen) { // 如果已经全屏就退出全屏 setState(() { SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.top]); _isFullScreen = false; }); } else { // 如果不是全屏就进入全屏 setState(() { SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersive, overlays: []); _isFullScreen = true; }); } }, onVerticalDragUpdate: (DragUpdateDetails details) { if (_isFullScreen) { // 如果是全屏就退出全屏 setState(() { SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.top]); _isFullScreen = false; }); } }, child: Container( color: Colors.white, // 设置容器背景颜色为白色 child: Center( child: Text('点击屏幕进入全屏,滑动屏幕退出全屏'), // 在屏幕中央显示文本 ), ), ); } @override void dispose() { _timer?.cancel(); // 取消定时器 super.dispose(); } }
---
标签:SystemChrome,SystemUiMode,状态栏,isFullScreen,全屏,去除,overlays,flutter,setEnabledSyst From: https://www.cnblogs.com/xbinbin/p/17898720.html