window top-level property

Window window

The Window singleton.

Please try to avoid statically referencing this and instead use a binding for dependency resolution such as WidgetsBinding.instance.window.

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 a Window is required before invoking runApp(). In that case, it is acceptable (though unfortunate) to use this object statically.


final Window window = Window._()