The desktop window
On macOS, Windows and Linux the native window is set from properties, before the first frame is shown: its title, the style of its title bar, and its initial, smallest and largest sizes. Two widgets help an app that draws its own title bar. Phones and the web ignore the keys.
Why
A desktop app usually needs native code in each runner (Swift, C++, C) to size its window or hide its title bar, or a plugin such as window_manager. Here it is configuration, per platform if needed (application-macos.yml), and the window appears already as set: no flicker from the runner's size to yours.
Example
# lib/resources/application-desktop.yml: macOS, Windows and Linux
spring:
flutter:
desktop:
window:
title: NEON Books # the title bar, Dock, taskbar
title-bar: transparent # default | transparent | hidden
initial-size: 1280x800 # logical pixels, centered
min-size: 800x600 # the user cannot drag smaller
max-size: 1920x1080 # ... or larger
The properties
| Key | Type | Default | Meaning |
|---|---|---|---|
spring.flutter.desktop.window.title |
text | the runner's (normally the app's name) | The window's title: what the OS shows in the title bar when it is visible (not with transparent or hidden) and in the Dock, taskbar and window switcher. Surrounding blanks are trimmed; a blank value is the same as none |
spring.flutter.desktop.window.title-bar |
default, transparent, hidden |
default |
default: the OS's title bar, untouched. transparent: the content is drawn under a transparent title bar and the window buttons stay over it. hidden: no title bar and no window buttons; the app draws its own |
spring.flutter.desktop.window.initial-size |
<width>x<height>, logical pixels |
the runner's size | The size of the content area when the window opens, centered on the screen (not under Wayland, where the compositor places windows) |
spring.flutter.desktop.window.min-size |
<width>x<height> |
none | The smallest content size the user can drag the window to |
spring.flutter.desktop.window.max-size |
<width>x<height> |
none | The largest content size the user can drag the window to |
A malformed size (1280x, a negative or zero number), or sizes that contradict each other (they must be min ≤ initial ≤ max), stops the start naming the values. On a phone or the web the keys are not read, even a malformed value.
The title bar per platform
| Style | macOS | Windows | Linux |
|---|---|---|---|
transparent |
Transparent title bar, hidden title, full-size content view; the traffic lights over the content | The frame extended into the client area; the system's caption buttons over the content | GTK draws no content under a header bar, so it becomes a flat header bar of its own with no title, with the window buttons |
hidden |
No title bar, no buttons | No caption | No decoration |
Maximizing a window with a max-size: macOS zoom stops at it, Windows maximizes to the largest allowed size, and a Linux window manager may refuse to maximize past it.
Drawing your own title bar
Widget build(BuildContext context) {
// Room for the traffic lights (macOS, at the left) or the caption
// buttons (Windows, at the right); zero with the default title bar.
final insets = DesktopWindow.insetsOf(context);
return WindowDragArea(
child: Padding(
padding: EdgeInsets.only(left: insets.left, right: insets.right),
child: const SizedBox(height: 48, child: Text('NEON Books')),
),
);
}
WindowDragAreastarts the OS's window drag once the pointer moves with the primary button down (so a click or a button inside it is not a drag), and a double click maximizes or restores the window as the OS does (doubleClickMaximizes: falseleaves it alone).DesktopWindow.insetsOf(context)gives the room the window buttons take;DesktopWindow.of(context)also tells the title bar style that was applied.
No flicker
The runners show the window with the first frame, so the starter holds the first frame back until the native side has set the window (at most five seconds). The window appears as set. An app without these properties pays nothing but that frame waiting for the environment.
The platform code is this package's own (a Flutter plugin, no window_manager): Swift on macOS, C++ on Windows, C on Linux. Not done yet: the window's position, and restoring the size and position the user left.