Flutter Desktop Apps: Getting Started

Mar 28 2023 · Dart 2.19, Flutter 3.7, Android Studio 2021.3.1 or higher, Visual Studo Code 1.7.4 or higher

Part 1: Flutter Desktop Apps

04. Setting & Limiting the Window Size

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 03. Create a Flutter Desktop App Next episode: 05. Create System Menus

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Transcript: 04. Setting & Limiting the Window Size

Todo App

If you’ve used Flutter before, you’ve seen the errors that happen when a widget overflows. This displays errors on the screen that will confuse the user. Since the user can change the size of the window that desktop apps are run on, this can cause display errors. You can prevent some of these errors by preventing the user from making the window too small.

You will use the desktop_window plugin that works on all three platforms. This plugin will allow you to set the current, minimum and maximum sizes as well as toggle between full screen.

Android Studio

Open up the starter project. In the project window, open up pubspec.yaml. After the path_provider package, add desktop_window: ^0.4.0. This will add the desktop_window plugin. Hit Pub get to download the plugin.

On the Mac, choose the MacOS (Desktop) device and run the app. Try to resize the app and see what happens when the window gets too small. You can see the errors that get shown when the window is too small.

Now, open up main.dart. After WidgetsFlutterBinding.ensureInitialized, add:

if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
  await DesktopWindow.setWindowSize(const Size(700,500));

  await DesktopWindow.setMinWindowSize(const Size(700,500));
  await DesktopWindow.setMaxWindowSize(Size.infinite);
}

This will check the platform to make sure this isn’t running on iOS or Android and set the current window size, the minimum window size and the maximum window size, which can be as big as possible.

Run the app again and check to make sure that the window cannot be sized too small. Great. Now you don’t have to worry about the user seeing the dreaded overflow images.