webブラウザ(webアプリ)だとウインドウの最小サイズはデフォルトで指定されているようですが、macOSアプリの場合自分で指定しないと相当小さくできるのでオーバーフローしてしまいました。
It seems that web browsers (web apps) have a default minimum window size, but in the case of macOS apps, if I don’t specify it myself, the window can be made considerably small, which caused an overflow issue.
StackOverflowなどにネイティブでやる方法もありますが、Flutterパッケージでやる方法を調べたので共有させていただきます。
There are native methods like on StackOverflow, but I researched how to do it with Flutter packages and would like to share that.
(1) desktop_window
https://pub.dev/packages/desktop_window
最終更新2年前らしいですね。。。
It seems the last update was about 2 years ago.
pub getはできました。
I was able to run pub get
.
まあ古いから絶対危ないということでもないですが。
Just because it’s old doesn’t necessarily mean it’s unsafe.
目的の最小サイズ指定は下記のコードできました。
I managed to set the minimum size with the following code.
確認はmacosのみです。一応Windowsも対応しているようです。
I’ve only tested this on macOS, but it seems to support Windows as well.
import 'package:desktop_window/desktop_window.dart'; //... Future<void> main() async { WidgetsFlutterBinding.ensureInitialized(); await DesktopWindow.setMinWindowSize(Size(500,600)); runApp( //...
(2) window_manager
https://pub.dev/packages/window_manager
こちらの方が最終更新日は新しいですね(40日前)。
This one has a more recent last update (40 days ago).
試してないですが、readmeを見ると機能も色々ありそうですねはい。
I haven’t tried it, but looking at the readme, it seems to have a variety of features.
こちらも最小サイズ指定は下記のコードでできました。
I was able to set the minimum size with the following code using this package as well.
こちらも確認はmacosのみですが、Windowsも対応しているようです。
I’ve only tested this on macOS as well, but it seems to support Windows as well.
import 'package:window_manager/window_manager.dart'; //... Future<void> main() async { //機能した。ミニマムサイズが指定できた。 WidgetsFlutterBinding.ensureInitialized(); await windowManager.ensureInitialized(); WindowOptions windowOptions = WindowOptions( size: Size(800, 600), center: true, backgroundColor: Colors.transparent, skipTaskbar: false, titleBarStyle: TitleBarStyle.hidden, ); windowManager.waitUntilReadyToShow(windowOptions, () async { await windowManager.show(); await windowManager.focus(); }); await windowManager.setMinimumSize(Size(800, 600)); runApp( //...
以上です。お読みいただきありがとうございました。
That’s all.
Thank you for reading.