Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,12 @@ class Locale {

/// The most basic interface to the host operating system's user interface.
///
/// It exposes the size of the display, the core scheduler API, the input event
/// callback, the graphics drawing API, and other such core services.
///
/// There is a single Window instance in the system, which you can
/// obtain from the [window] property.
/// obtain from `WidgetsBinding.instance.window`, or `window` in `dart:ui` if
/// `WidgetsBinding` is unavailable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we really want to incentivize the use of the singleton though, right? If window is imported directly from dart:ui then that usage cannot be dependency injected, can it? If I'm remembering that right then we should probably use some very strong language to push people towards the binding, if at all possible. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see below that you elaborated on this. I would suggest including a little bit of the seriousness of the issue in this reference, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to make it more serious and strong. Please let me know if it looks good, or if you have some sample text that I can follow (or copy/paste) :D

///
/// ## Insets and Padding
///
Expand Down Expand Up @@ -1220,7 +1224,19 @@ enum Brightness {
light,
}

/// The [Window] singleton. This object exposes the size of the display, the
/// core scheduler API, the input event callback, the graphics drawing API, and
/// other such core services.
/// 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._();