Describe Request
I wanna know how to set a window size that can't be changed. or Be changed at a locked aspect ratio
This is a temporary solution I made today:
import 'dart:io';
import 'package:flutter/widgets.dart';
import 'package:window_size/window_size.dart' as window_size;
import 'package:window_size/window_size.dart';
class WindowSizeService {
static const double width = 800;
static const double height = 500;
Future<PlatformWindow> _getPlatformWindow() async {
return await window_size.getWindowInfo();
}
void _setWindowSize(PlatformWindow platformWindow) {
final Rect frame = Rect.fromCenter(
center: Offset(
platformWindow.frame.center.dx,
platformWindow.frame.center.dy,
),
width: width,
height: height,
);
window_size.setWindowFrame(frame);
setWindowTitle(
'${Platform.operatingSystem} App',
);
if (Platform.isMacOS) {
window_size.setWindowMinSize(Size(width, height));
window_size.setWindowMaxSize(Size(width * 2, height * 2));
}
}
Future<void> initialize() async {
PlatformWindow platformWindow = await _getPlatformWindow();
if (platformWindow.screen != null) {
if (platformWindow.screen.visibleFrame.width != 800 ||
platformWindow.screen.visibleFrame.height != 500) {
_setWindowSize(platformWindow);
}
}
}
void setWindowTitle(String title) {
window_size.setWindowTitle(title);
}
}
Put the initialize method in the main function
Put the initialize method in every build method. Not the best solution but works.
To change the width and height, just change the variables at the top of the method 馃槉
I hope it helps 馃殌
If you want the window to be permanently unresizable a much, much better solution would be to just add the necessary native code to each runner to make the window unresizable. It's probably only a line or two on each platform.
My Problem is that I don't have experience in Native code of any platform. So I used what I had in hand. Although I might do a google search to figure it out. Meanwhile, I guess this is great!
Some behavior we noticed today:
The hope would be that whatever the behavior is, it's the same on all platforms.
- On Ubuntu, setting minSize prevents the window from being resized, we need to assign a large maxSize in order to enable resize.
Please file a new issue. That's not the correct behavior, but it's unrelated to this issue which is requesting fully disabling resize (which is not done via min and max size, but by separate window flags)
Most helpful comment
This is a temporary solution I made today:
Put the
initializemethod in the main functionPut the
initializemethod in everybuildmethod. Not the best solution but works.To change the width and height, just change the variables at the top of the method 馃槉
I hope it helps 馃殌