How to set default size of macos app in flutter?
There's now a plugin to do this, which is not a permanent thing as it is described as preliminary functionality before eventually being folded into the core libraries.
Using the plugin for now is still likely to be better than hard-coding directly modifying the native code, especially if you have multiple platforms you want to work on.
First add to the pubspec.yaml
something like:
dependencies:
...
window_size:
git:
url: git://github.com/google/flutter-desktop-embedding.git
path: plugins/window_size
ref: 927f8cbc09b35d85245c095f2db8df9b186f6618
Using the specific Git reference to include this, as shown above, will give you good control over when you choose to pull updated code and make any changes this might entail.
You can then access various functions to set min/max window sizes, or frame, or get the current values, e.g.:
...
import 'dart:io'
import 'package:window_size/window_size.dart';
...
void main() {
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
setWindowTitle("My Desktop App");
setWindowMinSize(Size(375, 750));
setWindowMaxSize(Size(600, 1000));
}
runApp(MyApp());
}
I hope this helps someone. I'll try and update this post when the real answer comes out. It seems likely that the interface will approximate what is presented in this library, but the feature set is likely to undergo some change.
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.
I am not sure if this 100% valid, but I was looking for possibility to set window size. I have found package as @karora mentioned, but I wanted to only set window size and move on. So we can make it using xcode.
In project folder open Runner.xcodeproj:
macos -> Runner.xcodeproj
Then in Xcode project find MainMenu.xib then you can resize your flutter window.
This package can help with it.
Size size = await DesktopWindow.getWindowSize();
print(size);
await DesktopWindow.setWindowSize(Size(500,500));
await DesktopWindow.setMinWindowSize(Size(400,400));
await DesktopWindow.setMaxWindowSize(Size(800,800));
await DesktopWindow.resetMaxWindowSize();
await DesktopWindow.toggleFullScreen();
bool isFullScreen = await DesktopWindow.getFullScreen();
await DesktopWindow.setFullScreen(true);
await DesktopWindow.setFullScreen(false);