我正在使用 Flutter 开发桌面应用程序。我希望应用程序以全屏模式运行。这个解决方案让我忙了一段时间。为了让您免于忙碌,我分享了一些例子。我的解决方案将用于在 Windows 和 Android 应用程序上以全屏模式运行。
Android 应用程序全屏的代码示例
小部件构建(BuildContext 上下文){
代码在这里
返回MaterialApp
SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarBrightness: Brightness.light,
systemNavigationBarIconBrightness: Brightness.dark,
systemNavigationBarColor: Colors.transparent,
systemNavigationBarDividerColor: Colors.transparent,
systemNavigationBarContrastEnforced: false,
systemStatusBarContrastEnforced: false);
SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: [SystemUiOverlay.top, SystemUiOverlay.bottom]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky,
overlays: [SystemUiOverlay.bottom]);
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
将其添加到包的 pubspec.yaml 文件中:
依赖关系: 窗口管理器:^0.3.7
用途: 导入'包:window_manager/window_manager.dart';
runApp(const MyApp()); 代码在这里
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();
windowManager.waitUntilReadyToShow().then((_) async {
await windowManager.setFullScreen(true);
await windowManager.show();
开发适用于 Windows 和 Android 的 Flutter 桌面全屏应用程序
很抱歉打扰您。我是 Flutter 新手,我正在使用此代码片段使我的应用程序在全屏模式下运行。不过,我想为用户提供通过按 F11 或 ESC 切换全屏的选项。你能帮我解决这个问题吗?”