How to config the initial window size
I tried both this package and window_size of flutter-desktop-embedding. They are all first show the initial default sized window, then resize or move it. So a window blink will still exist.
Is there any way to set the initial size of the startup window without show-resize-move steps?
desktop_window: ^0.3.0
window_size:
git:
url: git://github.com/google/flutter-desktop-embedding.git
path: plugins/window_size
import 'package:desktop_window/desktop_window.dart';
import 'package:flutter/material.dart';
import 'package:system_network_proxy/app.dart';
import 'package:system_network_proxy/flutter_configuration.dart';
import 'package:system_network_proxy/service.dart';
import 'dart:io' show Platform;
import 'dart:math' as math;
import 'package:window_size/window_size.dart' as window_size;
/// global configuration from yaml
FlutterConfiguration config;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// await DesktopWindow.setWindowSize(Size(500, 300));
var window = await window_size.getWindowInfo();
if (window.screen != null) {
final screenFrame = window.screen.visibleFrame;
final width = 500.0;
final height = 300.0;
final left = ((screenFrame.width - width) / 2).roundToDouble();
final top = ((screenFrame.height - height) / 3).roundToDouble();
final frame = Rect.fromLTWH(left, top, width, height);
window_size.setWindowFrame(frame);
window_size.setWindowMinSize(Size(1.0 * width, 1.0 * height));
window_size.setWindowMaxSize(Size(1.0 * width, 1.0 * height));
window_size.setWindowTitle('System Network Proxy (${Platform.operatingSystem})');
}
config = await FlutterConfiguration.fromAsset('assets/config.yaml');
await Service().init();
runApp(App());
}
I don't think it's possible as of now.
Looking at the generated source code for macOS(MainFlutterWindow.swift) and Windows(main.cpp), the window frame is hard coded. macOS sets to default window size of NSWindow. Windows sets it to (10,10,1280,720)! Generated source code has to be edited to achieve set initial window frame. I don't think it's possible to do it with Flutter without changing generated native code.
@mix1009 Thanks, I saw the generated code (windows: windows\runner\main.cpp, linux: linux\my_application.cc, macos: macos\Runner\MainFlutterWindow.swift), it is hard coded indeed. So Maybe I can only modify the generated code to achieve this purpose. 😃