Skip to content

Commit 62f2844

Browse files
authored
Revert "Deprecate SingletonFlutterWindow and global window singleton (flutter#39302)" (flutter#40507)
Revert "Deprecate SingletonFlutterWindow and global window singleton"
1 parent 6597218 commit 62f2844

File tree

1 file changed

+36
-65
lines changed

1 file changed

+36
-65
lines changed

lib/ui/window.dart

Lines changed: 36 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -308,36 +308,22 @@ class FlutterView {
308308
external static void _updateSemantics(SemanticsUpdate update);
309309
}
310310

311-
/// Deprecated. Will be removed in a future version of Flutter.
311+
/// A [FlutterView] that includes access to setting callbacks and retrieving
312+
/// properties that reside on the [PlatformDispatcher].
312313
///
313-
/// This class is deprecated to prepare for Flutter's upcoming support for
314-
/// multiple views and eventually multiple windows.
314+
/// It is the type of the global [window] singleton used by applications that
315+
/// only have a single main window.
315316
///
316-
/// This class has been split into two classes: [FlutterView] and
317-
/// [PlatformDispatcher]. A [FlutterView] gives an application access to
318-
/// view-specific functionality while the [PlatformDispatcher] contains
319-
/// platform-specific functionality that applies to all views.
317+
/// In addition to the properties of [FlutterView], this class provides access
318+
/// to platform-specific properties. To modify or retrieve these properties,
319+
/// applications designed for more than one main window should prefer using
320+
/// `WidgetsBinding.instance.platformDispatcher` instead.
320321
///
321-
/// This class backs the global [window] singleton, which is also deprecated.
322-
/// See the docs on [window] for migration options.
323-
///
324-
/// See also:
325-
///
326-
/// * [FlutterView], which gives an application access to view-specific
327-
/// functionality.
328-
/// * [PlatformDispatcher], which gives an application access to
329-
/// platform-specific functionality.
330-
@Deprecated(
331-
'Use FlutterView or PlatformDispatcher instead. '
332-
'Deprecated to prepare for the upcoming multi-window support. '
333-
'This feature was deprecated after v3.7.0-32.0.pre.'
334-
)
322+
/// Prefer access through `WidgetsBinding.instance.window` or
323+
/// `WidgetsBinding.instance.platformDispatcher` over a static reference to
324+
/// [window], or [PlatformDispatcher.instance]. See the documentation for
325+
/// [PlatformDispatcher.instance] for more details about this recommendation.
335326
class SingletonFlutterWindow extends FlutterView {
336-
@Deprecated(
337-
'Use FlutterView or PlatformDispatcher instead. '
338-
'Deprecated to prepare for the upcoming multi-window support. '
339-
'This feature was deprecated after v3.7.0-32.0.pre.'
340-
)
341327
SingletonFlutterWindow._(super.windowId, super.platformDispatcher)
342328
: super._();
343329

@@ -590,7 +576,7 @@ class SingletonFlutterWindow extends FlutterView {
590576
/// {@macro dart.ui.window.accessorForwardWarning}
591577
///
592578
/// It's preferred to use [SchedulerBinding.addTimingsCallback] than to use
593-
/// [PlatformDispatcher.onReportTimings] directly because
579+
/// [SingletonFlutterWindow.onReportTimings] directly because
594580
/// [SchedulerBinding.addTimingsCallback] allows multiple callbacks.
595581
///
596582
/// This can be used to see if the window has missed frames (through
@@ -905,51 +891,36 @@ enum Brightness {
905891
light,
906892
}
907893

908-
/// Deprecated. Will be removed in a future version of Flutter.
909-
///
910-
/// This global property is deprecated to prepare for Flutter's upcoming support
911-
/// for multiple views and multiple windows.
894+
/// The [SingletonFlutterWindow] representing the main window for applications
895+
/// where there is only one window, such as applications designed for
896+
/// single-display mobile devices.
912897
///
913-
/// It represents the main view for applications where there is only one
914-
/// view, such as applications designed for single-display mobile devices.
915-
/// If the embedder supports multiple views, it points to the first view
916-
/// created which is assumed to be the main view. It throws if no view has
917-
/// been created yet or if the first view has been removed again.
898+
/// Applications that are designed to use more than one window should interact
899+
/// with the `WidgetsBinding.instance.platformDispatcher` instead.
918900
///
919-
/// The following options exists to migrate code that relies on accessing
920-
/// this deprecated property:
901+
/// Consider avoiding static references to this singleton through
902+
/// [PlatformDispatcher.instance] and instead prefer using a binding for
903+
/// dependency resolution such as `WidgetsBinding.instance.window`.
921904
///
922-
/// If a [BuildContext] is available, consider looking up the current
923-
/// [FlutterView] associated with that context via [View.of]. It gives access
924-
/// to the same functionality as this deprecated property. However, the
925-
/// platform-specific functionality has moved to the [PlatformDispatcher],
926-
/// which may be accessed from the view returned by [View.of] via
927-
/// [FlutterView.platformDispatcher]. Using [View.of] with a [BuildContext] is
928-
/// the preferred option to migrate away from this deprecated [window]
929-
/// property.
905+
/// Static access of this `window` object means that Flutter has few, if any
906+
/// options to fake or mock the given object in tests. Even in cases where Dart
907+
/// offers special language constructs to forcefully shadow such properties,
908+
/// those mechanisms would only be reasonable for tests and they would not be
909+
/// reasonable for a future of Flutter where we legitimately want to select an
910+
/// appropriate implementation at runtime.
930911
///
931-
/// If no context is available to look up a [FlutterView], the
932-
/// [PlatformDispatcher] can be used directly for platform-specific
933-
/// functionality. It also maintains a list of all available [FlutterView]s in
934-
/// [PlatformDispatcher.views] to access view-specific functionality without a
935-
/// context. If possible, consider accessing the [PlatformDispatcher] via the
936-
/// binding (e.g. `WidgetsBinding.instance.platformDispatcher`) instead of the
937-
/// static singleton [PlatformDispatcher.instance]. See
938-
/// [PlatformDispatcher.instance] for more information about why this is
939-
/// preferred.
912+
/// The only place that `WidgetsBinding.instance.window` is inappropriate is if
913+
/// access to these APIs is required before the binding is initialized by
914+
/// invoking `runApp()` or `WidgetsFlutterBinding.instance.ensureInitialized()`.
915+
/// In that case, it is necessary (though unfortunate) to use the
916+
/// [PlatformDispatcher.instance] object statically.
940917
///
941918
/// See also:
942919
///
943-
/// * [FlutterView], which gives an application access to view-specific
944-
/// functionality.
945-
/// * [PlatformDispatcher], which gives an application access to
946-
/// platform-specific functionality.
947-
/// * [PlatformDispatcher.views], for a list of all available views.
948-
@Deprecated(
949-
'Look up the current FlutterView from the context via View.of(context) or consult the PlatformDispatcher directly instead. '
950-
'Deprecated to prepare for the upcoming multi-window support. '
951-
'This feature was deprecated after v3.7.0-32.0.pre.'
952-
)
920+
/// * [PlatformDispatcher.views], contains the current list of Flutter windows
921+
/// belonging to the application, including top level application windows like
922+
/// this one.
923+
/// * [PlatformDispatcher.implicitView], this window's view.
953924
final SingletonFlutterWindow window = SingletonFlutterWindow._(0, PlatformDispatcher.instance);
954925

955926
/// Additional data available on each flutter frame.

0 commit comments

Comments
 (0)