如何让系统在平板电脑上以横向模式居中我的 Flutter 应用程序?

问题描述 投票:0回答:1

我想将 Flutter 应用程序在平板电脑上以横向模式居中,如图所示

flutter
1个回答
0
投票

如果我没记错的话,这是肖像模式,但没关系。

如果您希望在平板电脑或台式机屏幕中央显示您的应用程序,请尝试使用 window_manager 包。

将其添加为依赖项:

dependencies:
  window_manager: ^0.3.8

用途:

  import 'package:flutter/material.dart';
  import 'package:window_manager/window_manager.dart';
        
    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
      // Must add this line.
      await windowManager.ensureInitialized();
    
      WindowOptions windowOptions = WindowOptions(
        size: Size(800, 600), // initial size of the app screen
        center: true,  // display app on center
        backgroundColor: Colors.transparent,
        skipTaskbar: false,
        titleBarStyle: TitleBarStyle.hidden,
      );
      windowManager.waitUntilReadyToShow(windowOptions, () async {
        await windowManager.show();
        await windowManager.focus();
      });
    
      runApp(MyApp());
    }

没关系,什么方向模式,应用程序都会在屏幕上居中。

希望对您有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.