如何在Flutter中设置MacOS应用程序的默认大小? [英] How to set default size of macos app in flutter?

查看:475
本文介绍了如何在Flutter中设置MacOS应用程序的默认大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用flutter构建macOS桌面应用程序.我希望该应用程序为全宽,边缘到边缘.但是,当我通过模拟器或在构建后运行该应用程序时,它始终会启动大小为800x600的应用程序.

I am trying to build a macOS desktop app with flutter. I want the app to be full-width, edge-to-edge. However, when I run the app via the simulator, or after the build, it always launches the app with size 800x600.

我已将根容器的高度和宽度设置为double.infinity.实际上,即使我将高度和宽度设置为10.0,它始终会以800x600的速度启动该应用程序.我是新手,所以可能缺少一些基本知识.我碰到过的大多数教程都谈论构建移动应用程序,这从来都不是问题,因为该应用程序始终以完整宽度启动.

I have set the height and width of the root container to double.infinity. In fact, even if I set the height and width to 10.0, it always launches the app with 800x600. I am new to flutter, so probably missing some fundamentals. Most tutorials I have come across talk about building a mobile app where this is never a problem because the app always launches to its full width.

这是我的整个测试应用代码:

Here is my entire test app code:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(color: Colors.white),
      height: double.infinity,
      width: double.infinity,
      child: Center(
        child: Text(
          'Hello World',
          textDirection: TextDirection.ltr,
          style: TextStyle(
              fontSize: 32, fontWeight: FontWeight.bold, color: Colors.black),
        ),
      ),
    );
  }
}

推荐答案

当前控制初始大小的唯一方法是使用本机代码(遵循以下问题: 2 找出变化的时间).您最有可能希望在macos/Runner/MainFlutterWindow.swift中进行设置.

Currently the only way to control the initial size is in native code (follow these issues: 1 and 2 to find out when that changes). You'd most likely want to set it in macos/Runner/MainFlutterWindow.swift.

从描述中不清楚是要启动到全屏模式,还是仅具有一个标准的窗口,其大小为屏幕工作区的大小;所涉及的代码会有所不同,具体取决于您要完成的工作.

It's not clear from your description whether you want to launch into full-screen mode, or just have a standard window the size of the client area of the screen; the code involved would be different depending on which you are trying to accomplish.

这篇关于如何在Flutter中设置MacOS应用程序的默认大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆