window top-level property Null safety
The SingletonFlutterWindow representing the main window for applications where there is only one window, such as applications designed for single-display mobile devices.
Applications that are designed to use more than one window should interact
Consider avoiding static references to this singleton through
PlatformDispatcher.instance and instead prefer using a binding for
dependency resolution such as
Static access of this
window object means that Flutter has few, if any
options to fake or mock the given object in tests. Even in cases where Dart
offers special language constructs to forcefully shadow such properties,
those mechanisms would only be reasonable for tests and they would not be
reasonable for a future of Flutter where we legitimately want to select an
appropriate implementation at runtime.
The only place that
WidgetsBinding.instance.window is inappropriate is if
access to these APIs is required before the binding is initialized by
In that case, it is necessary (though unfortunate) to use the
PlatformDispatcher.instance object statically.
- PlatformDispatcher.views, contains the current list of Flutter windows belonging to the application, including top level application windows like this one.
final SingletonFlutterWindow window = SingletonFlutterWindow._(0, PlatformDispatcher.instance);