This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Reland "Deprecate SingletonFlutterWindow and global window singleton (#39302)" #40511
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -308,22 +308,36 @@ class FlutterView { | |
| external static void _updateSemantics(SemanticsUpdate update); | ||
| } | ||
|
|
||
| /// A [FlutterView] that includes access to setting callbacks and retrieving | ||
| /// properties that reside on the [PlatformDispatcher]. | ||
| /// Deprecated. Will be removed in a future version of Flutter. | ||
| /// | ||
| /// It is the type of the global [window] singleton used by applications that | ||
| /// only have a single main window. | ||
| /// This class is deprecated to prepare for Flutter's upcoming support for | ||
| /// multiple views and eventually multiple windows. | ||
| /// | ||
| /// In addition to the properties of [FlutterView], this class provides access | ||
| /// to platform-specific properties. To modify or retrieve these properties, | ||
| /// applications designed for more than one main window should prefer using | ||
| /// `WidgetsBinding.instance.platformDispatcher` instead. | ||
| /// This class has been split into two classes: [FlutterView] and | ||
| /// [PlatformDispatcher]. A [FlutterView] gives an application access to | ||
| /// view-specific functionality while the [PlatformDispatcher] contains | ||
| /// platform-specific functionality that applies to all views. | ||
| /// | ||
| /// Prefer access through `WidgetsBinding.instance.window` or | ||
| /// `WidgetsBinding.instance.platformDispatcher` over a static reference to | ||
| /// [window], or [PlatformDispatcher.instance]. See the documentation for | ||
| /// [PlatformDispatcher.instance] for more details about this recommendation. | ||
| /// This class backs the global [window] singleton, which is also deprecated. | ||
| /// See the docs on [window] for migration options. | ||
| /// | ||
| /// See also: | ||
| /// | ||
| /// * [FlutterView], which gives an application access to view-specific | ||
| /// functionality. | ||
| /// * [PlatformDispatcher], which gives an application access to | ||
| /// platform-specific functionality. | ||
| @Deprecated( | ||
| 'Use FlutterView or PlatformDispatcher instead. ' | ||
| 'Deprecated to prepare for the upcoming multi-window support. ' | ||
| 'This feature was deprecated after v3.7.0-32.0.pre.' | ||
| ) | ||
| class SingletonFlutterWindow extends FlutterView { | ||
| @Deprecated( | ||
| 'Use FlutterView or PlatformDispatcher instead. ' | ||
| 'Deprecated to prepare for the upcoming multi-window support. ' | ||
| 'This feature was deprecated after v3.7.0-32.0.pre.' | ||
| ) | ||
| SingletonFlutterWindow._(super.windowId, super.platformDispatcher) | ||
| : super._(); | ||
|
|
||
|
|
@@ -576,7 +590,7 @@ class SingletonFlutterWindow extends FlutterView { | |
| /// {@macro dart.ui.window.accessorForwardWarning} | ||
| /// | ||
| /// It's preferred to use [SchedulerBinding.addTimingsCallback] than to use | ||
| /// [SingletonFlutterWindow.onReportTimings] directly because | ||
| /// [PlatformDispatcher.onReportTimings] directly because | ||
| /// [SchedulerBinding.addTimingsCallback] allows multiple callbacks. | ||
| /// | ||
| /// This can be used to see if the window has missed frames (through | ||
|
|
@@ -891,36 +905,51 @@ enum Brightness { | |
| light, | ||
| } | ||
|
|
||
| /// The [SingletonFlutterWindow] representing the main window for applications | ||
| /// where there is only one window, such as applications designed for | ||
| /// single-display mobile devices. | ||
| /// Deprecated. Will be removed in a future version of Flutter. | ||
| /// | ||
| /// This global property is deprecated to prepare for Flutter's upcoming support | ||
| /// for multiple views and multiple windows. | ||
| /// | ||
| /// Applications that are designed to use more than one window should interact | ||
| /// with the `WidgetsBinding.instance.platformDispatcher` instead. | ||
| /// It represents the main view for applications where there is only one | ||
| /// view, such as applications designed for single-display mobile devices. | ||
| /// If the embedder supports multiple views, it points to the first view | ||
| /// created which is assumed to be the main view. It throws if no view has | ||
| /// been created yet or if the first view has been removed again. | ||
| /// | ||
| /// Consider avoiding static references to this singleton through | ||
| /// [PlatformDispatcher.instance] and instead prefer using a binding for | ||
| /// dependency resolution such as `WidgetsBinding.instance.window`. | ||
| /// The following options exists to migrate code that relies on accessing | ||
| /// this deprecated property: | ||
| /// | ||
| /// 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. | ||
| /// If a [BuildContext] is available, consider looking up the current | ||
| /// [FlutterView] associated with that context via [View.of]. It gives access | ||
| /// to the same functionality as this deprecated property. However, the | ||
| /// platform-specific functionality has moved to the [PlatformDispatcher], | ||
| /// which may be accessed from the view returned by [View.of] via | ||
| /// [FlutterView.platformDispatcher]. Using [View.of] with a [BuildContext] is | ||
| /// the preferred option to migrate away from this deprecated [window] | ||
| /// property. | ||
| /// | ||
| /// The only place that `WidgetsBinding.instance.window` is inappropriate is if | ||
| /// access to these APIs is required before the binding is initialized by | ||
| /// invoking `runApp()` or `WidgetsFlutterBinding.instance.ensureInitialized()`. | ||
| /// In that case, it is necessary (though unfortunate) to use the | ||
| /// [PlatformDispatcher.instance] object statically. | ||
| /// If no context is available to look up a [FlutterView], the | ||
| /// [PlatformDispatcher] can be used directly for platform-specific | ||
| /// functionality. It also maintains a list of all available [FlutterView]s in | ||
| /// [PlatformDispatcher.views] to access view-specific functionality without a | ||
| /// context. If possible, consider accessing the [PlatformDispatcher] via the | ||
| /// binding (e.g. `WidgetsBinding.instance.platformDispatcher`) instead of the | ||
| /// static singleton [PlatformDispatcher.instance]. See | ||
| /// [PlatformDispatcher.instance] for more information about why this is | ||
| /// preferred. | ||
| /// | ||
| /// See also: | ||
| /// | ||
| /// * [PlatformDispatcher.views], contains the current list of Flutter windows | ||
| /// belonging to the application, including top level application windows like | ||
| /// this one. | ||
| /// * [PlatformDispatcher.implicitView], this window's view. | ||
| /// * [FlutterView], which gives an application access to view-specific | ||
| /// functionality. | ||
| /// * [PlatformDispatcher], which gives an application access to | ||
| /// platform-specific functionality. | ||
| /// * [PlatformDispatcher.views], for a list of all available views. | ||
| @Deprecated( | ||
| 'Look up the current FlutterView from the context via View.of(context) or consult the PlatformDispatcher directly instead. ' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's short enough, you could add the method to call on
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already super-long in the analyzer output. I'm gonna skip this :) |
||
| 'Deprecated to prepare for the upcoming multi-window support. ' | ||
| 'This feature was deprecated after v3.7.0-32.0.pre.' | ||
| ) | ||
| final SingletonFlutterWindow window = SingletonFlutterWindow._(0, PlatformDispatcher.instance); | ||
|
|
||
| /// Additional data available on each flutter frame. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.