Remove MediaQuery from WidgetsApp (#119377)
* Remove MediaQuery from WidgetsApp
* more
* fix test
* more deprecation notices.
diff --git a/packages/flutter/lib/src/cupertino/app.dart b/packages/flutter/lib/src/cupertino/app.dart
index 8aface4..633cd08 100644
--- a/packages/flutter/lib/src/cupertino/app.dart
+++ b/packages/flutter/lib/src/cupertino/app.dart
@@ -176,6 +176,11 @@
this.actions,
this.restorationScopeId,
this.scrollBehavior,
+ @Deprecated(
+ 'Remove this parameter as it is now ignored. '
+ 'CupertinoApp never introduces its own MediaQuery; the View widget takes care of that. '
+ 'This feature was deprecated after v3.7.0-29.0.pre.'
+ )
this.useInheritedMediaQuery = false,
}) : routeInformationProvider = null,
routeInformationParser = null,
@@ -212,6 +217,11 @@
this.actions,
this.restorationScopeId,
this.scrollBehavior,
+ @Deprecated(
+ 'Remove this parameter as it is now ignored. '
+ 'CupertinoApp never introduces its own MediaQuery; the View widget takes care of that. '
+ 'This feature was deprecated after v3.7.0-29.0.pre.'
+ )
this.useInheritedMediaQuery = false,
}) : assert(routerDelegate != null || routerConfig != null),
navigatorObservers = null,
@@ -408,6 +418,11 @@
final ScrollBehavior? scrollBehavior;
/// {@macro flutter.widgets.widgetsApp.useInheritedMediaQuery}
+ @Deprecated(
+ 'This setting is now ignored. '
+ 'CupertinoApp never introduces its own MediaQuery; the View widget takes care of that. '
+ 'This feature was deprecated after v3.7.0-29.0.pre.'
+ )
final bool useInheritedMediaQuery;
@override
@@ -541,7 +556,6 @@
shortcuts: widget.shortcuts,
actions: widget.actions,
restorationScopeId: widget.restorationScopeId,
- useInheritedMediaQuery: widget.useInheritedMediaQuery,
);
}
return WidgetsApp(
@@ -576,7 +590,6 @@
shortcuts: widget.shortcuts,
actions: widget.actions,
restorationScopeId: widget.restorationScopeId,
- useInheritedMediaQuery: widget.useInheritedMediaQuery,
);
}
diff --git a/packages/flutter/lib/src/material/app.dart b/packages/flutter/lib/src/material/app.dart
index 10ccaf7..ce49ccd 100644
--- a/packages/flutter/lib/src/material/app.dart
+++ b/packages/flutter/lib/src/material/app.dart
@@ -241,6 +241,11 @@
this.actions,
this.restorationScopeId,
this.scrollBehavior,
+ @Deprecated(
+ 'Remove this parameter as it is now ignored. '
+ 'MaterialApp never introduces its own MediaQuery; the View widget takes care of that. '
+ 'This feature was deprecated after v3.7.0-29.0.pre.'
+ )
this.useInheritedMediaQuery = false,
}) : routeInformationProvider = null,
routeInformationParser = null,
@@ -285,6 +290,11 @@
this.actions,
this.restorationScopeId,
this.scrollBehavior,
+ @Deprecated(
+ 'Remove this parameter as it is now ignored. '
+ 'MaterialApp never introduces its own MediaQuery; the View widget takes care of that. '
+ 'This feature was deprecated after v3.7.0-29.0.pre.'
+ )
this.useInheritedMediaQuery = false,
}) : assert(routerDelegate != null || routerConfig != null),
navigatorObservers = null,
@@ -733,6 +743,11 @@
final bool debugShowMaterialGrid;
/// {@macro flutter.widgets.widgetsApp.useInheritedMediaQuery}
+ @Deprecated(
+ 'This setting is now ignored. '
+ 'MaterialApp never introduces its own MediaQuery; the View widget takes care of that. '
+ 'This feature was deprecated after v3.7.0-29.0.pre.'
+ )
final bool useInheritedMediaQuery;
@override
@@ -983,7 +998,6 @@
shortcuts: widget.shortcuts,
actions: widget.actions,
restorationScopeId: widget.restorationScopeId,
- useInheritedMediaQuery: widget.useInheritedMediaQuery,
);
}
@@ -1019,7 +1033,6 @@
shortcuts: widget.shortcuts,
actions: widget.actions,
restorationScopeId: widget.restorationScopeId,
- useInheritedMediaQuery: widget.useInheritedMediaQuery,
);
}
diff --git a/packages/flutter/lib/src/widgets/app.dart b/packages/flutter/lib/src/widgets/app.dart
index 9e915a7..0648243 100644
--- a/packages/flutter/lib/src/widgets/app.dart
+++ b/packages/flutter/lib/src/widgets/app.dart
@@ -241,9 +241,6 @@
/// It is used by both [MaterialApp] and [CupertinoApp] to implement base
/// functionality for an app.
///
-/// Builds a [MediaQuery] using [MediaQuery.fromWindow]. To use an inherited
-/// [MediaQuery] instead, set [useInheritedMediaQuery] to true.
-///
/// Find references to many of the widgets that [WidgetsApp] wraps in the "See
/// also" section.
///
@@ -343,6 +340,11 @@
this.shortcuts,
this.actions,
this.restorationScopeId,
+ @Deprecated(
+ 'Remove this parameter as it is now ignored. '
+ 'WidgetsApp never introduces its own MediaQuery; the View widget takes care of that. '
+ 'This feature was deprecated after v3.7.0-29.0.pre.'
+ )
this.useInheritedMediaQuery = false,
}) : assert(
home == null ||
@@ -437,6 +439,11 @@
this.shortcuts,
this.actions,
this.restorationScopeId,
+ @Deprecated(
+ 'Remove this parameter as it is now ignored. '
+ 'WidgetsApp never introduces its own MediaQuery; the View widget takes care of that. '
+ 'This feature was deprecated after v3.7.0-29.0.pre.'
+ )
this.useInheritedMediaQuery = false,
}) : assert((){
if (routerConfig != null) {
@@ -1153,11 +1160,16 @@
final String? restorationScopeId;
/// {@template flutter.widgets.widgetsApp.useInheritedMediaQuery}
- /// If true, an inherited MediaQuery will be used. If one is not available,
- /// or this is false, one will be built from the window.
+ /// Deprecated. This setting is not ignored.
///
- /// Cannot be null, defaults to false.
+ /// The widget never introduces its own [MediaQuery]; the [View] widget takes
+ /// care of that.
/// {@endtemplate}
+ @Deprecated(
+ 'This setting is now ignored. '
+ 'WidgetsApp never introduces its own MediaQuery; the View widget takes care of that. '
+ 'This feature was deprecated after v3.7.0-29.0.pre.'
+ )
final bool useInheritedMediaQuery;
/// If true, forces the performance overlay to be visible in all instances.
@@ -1724,18 +1736,6 @@
assert(_debugCheckLocalizations(appLocale));
- Widget child = Localizations(
- locale: appLocale,
- delegates: _localizationsDelegates.toList(),
- child: title,
- );
-
- if (!widget.useInheritedMediaQuery || MediaQuery.maybeOf(context) == null) {
- child = MediaQuery.fromWindow(
- child: child,
- );
- }
-
return RootRestorationScope(
restorationId: widget.restorationScopeId,
child: SharedAppData(
@@ -1754,7 +1754,11 @@
policy: ReadingOrderTraversalPolicy(),
child: TapRegionSurface(
child: ShortcutRegistrar(
- child: child,
+ child: Localizations(
+ locale: appLocale,
+ delegates: _localizationsDelegates.toList(),
+ child: title,
+ ),
),
),
),
diff --git a/packages/flutter/test/material/debug_test.dart b/packages/flutter/test/material/debug_test.dart
index c9f7a3b..e89a65c 100644
--- a/packages/flutter/test/material/debug_test.dart
+++ b/packages/flutter/test/material/debug_test.dart
@@ -192,8 +192,6 @@
' _LocalizationsScope-[GlobalKey#00000]\n'
' Semantics\n'
' Localizations\n'
- ' MediaQuery\n'
- ' _MediaQueryFromView\n'
' Semantics\n'
' _FocusInheritedScope\n'
' Focus\n'
diff --git a/packages/flutter/test/material/snack_bar_test.dart b/packages/flutter/test/material/snack_bar_test.dart
index bc1c699..cbd6542 100644
--- a/packages/flutter/test/material/snack_bar_test.dart
+++ b/packages/flutter/test/material/snack_bar_test.dart
@@ -1530,72 +1530,72 @@
expect(snackBarBottomLeft, equals(bottomNavigationBarTopLeft));
},
);
-
- testWidgets(
- 'Padding of $behavior is not consumed by viewInsets',
- (WidgetTester tester) async {
- final Widget child = MaterialApp(
- home: Scaffold(
- resizeToAvoidBottomInset: false,
- floatingActionButton: FloatingActionButton(
- child: const Icon(Icons.send),
- onPressed: () {},
- ),
- body: Builder(
- builder: (BuildContext context) {
- return GestureDetector(
- onTap: () {
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content: const Text('I am a snack bar.'),
- duration: const Duration(seconds: 2),
- action: SnackBarAction(label: 'ACTION', onPressed: () {}),
- behavior: behavior,
- ),
- );
- },
- child: const Text('X'),
- );
- },
- ),
- ),
- );
-
- await tester.pumpWidget(
- MediaQuery(
- data: const MediaQueryData(
- padding: EdgeInsets.only(bottom: 20.0),
- ),
- child: child,
- ),
- );
- await tester.tap(find.text('X'));
- await tester.pumpAndSettle(); // Show snackbar
- final Offset initialBottomLeft = tester.getBottomLeft(find.byType(SnackBar));
- final Offset initialBottomRight = tester.getBottomRight(find.byType(SnackBar));
- // Consume bottom padding - as if by the keyboard opening
- await tester.pumpWidget(
- MediaQuery(
- data: const MediaQueryData(
- viewPadding: EdgeInsets.all(20),
- viewInsets: EdgeInsets.all(100),
- ),
- child: child,
- ),
- );
- await tester.tap(find.text('X'));
- await tester.pumpAndSettle(); // Have the SnackBar fully animate out.
-
- final Offset finalBottomLeft = tester.getBottomLeft(find.byType(SnackBar));
- final Offset finalBottomRight = tester.getBottomRight(find.byType(SnackBar));
-
- expect(initialBottomLeft, finalBottomLeft);
- expect(initialBottomRight, finalBottomRight);
- },
- );
}
testWidgets(
+ 'Padding of ${SnackBarBehavior.fixed} is not consumed by viewInsets',
+ (WidgetTester tester) async {
+ final Widget child = MaterialApp(
+ home: Scaffold(
+ resizeToAvoidBottomInset: false,
+ floatingActionButton: FloatingActionButton(
+ child: const Icon(Icons.send),
+ onPressed: () {},
+ ),
+ body: Builder(
+ builder: (BuildContext context) {
+ return GestureDetector(
+ onTap: () {
+ ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(
+ content: const Text('I am a snack bar.'),
+ duration: const Duration(seconds: 2),
+ action: SnackBarAction(label: 'ACTION', onPressed: () {}),
+ behavior: SnackBarBehavior.fixed,
+ ),
+ );
+ },
+ child: const Text('X'),
+ );
+ },
+ ),
+ ),
+ );
+
+ await tester.pumpWidget(
+ MediaQuery(
+ data: const MediaQueryData(
+ padding: EdgeInsets.only(bottom: 20.0),
+ ),
+ child: child,
+ ),
+ );
+ await tester.tap(find.text('X'));
+ await tester.pumpAndSettle(); // Show snackbar
+ final Offset initialBottomLeft = tester.getBottomLeft(find.byType(SnackBar));
+ final Offset initialBottomRight = tester.getBottomRight(find.byType(SnackBar));
+ // Consume bottom padding - as if by the keyboard opening
+ await tester.pumpWidget(
+ MediaQuery(
+ data: const MediaQueryData(
+ viewPadding: EdgeInsets.all(20),
+ viewInsets: EdgeInsets.all(100),
+ ),
+ child: child,
+ ),
+ );
+ await tester.tap(find.text('X'));
+ await tester.pumpAndSettle(); // Have the SnackBar fully animate out.
+
+ final Offset finalBottomLeft = tester.getBottomLeft(find.byType(SnackBar));
+ final Offset finalBottomRight = tester.getBottomRight(find.byType(SnackBar));
+
+ expect(initialBottomLeft, finalBottomLeft);
+ expect(initialBottomRight, finalBottomRight);
+ },
+ );
+
+ testWidgets(
'${SnackBarBehavior.fixed} should align SnackBar with the bottom of Scaffold '
'when Scaffold has a FloatingActionButton',
(WidgetTester tester) async {
diff --git a/packages/flutter/test/widgets/app_test.dart b/packages/flutter/test/widgets/app_test.dart
index 6d58a4a..15ab3f9 100644
--- a/packages/flutter/test/widgets/app_test.dart
+++ b/packages/flutter/test/widgets/app_test.dart
@@ -595,55 +595,6 @@
expect(tester.takeException(), "Warning: This application's locale, C_UTF-8, is not supported by all of its localization delegates.");
});
- testWidgets('WidgetsApp creates a MediaQuery if `useInheritedMediaQuery` is set to false', (WidgetTester tester) async {
- late BuildContext capturedContext;
- await tester.pumpWidget(
- WidgetsApp(
- builder: (BuildContext context, Widget? child) {
- capturedContext = context;
- return const Placeholder();
- },
- color: const Color(0xFF123456),
- ),
- );
- expect(MediaQuery.of(capturedContext), isNotNull);
- });
-
- testWidgets('WidgetsApp does not create MediaQuery if `useInheritedMediaQuery` is set to true and one is available', (WidgetTester tester) async {
- late BuildContext capturedContext;
- final UniqueKey uniqueKey = UniqueKey();
- await tester.pumpWidget(
- MediaQuery(
- key: uniqueKey,
- data: const MediaQueryData(),
- child: WidgetsApp(
- useInheritedMediaQuery: true,
- builder: (BuildContext context, Widget? child) {
- capturedContext = context;
- return const Placeholder();
- },
- color: const Color(0xFF123456),
- ),
- ),
- );
- expect(capturedContext.dependOnInheritedWidgetOfExactType<MediaQuery>()?.key, uniqueKey);
- });
-
- testWidgets('WidgetsApp does create a MediaQuery if `useInheritedMediaQuery` is set to true and none is available', (WidgetTester tester) async {
- late BuildContext capturedContext;
- await tester.pumpWidget(
- WidgetsApp(
- useInheritedMediaQuery: true,
- builder: (BuildContext context, Widget? child) {
- capturedContext = context;
- return const Placeholder();
- },
- color: const Color(0xFF123456),
- ),
- );
- expect(MediaQuery.of(capturedContext), isNotNull);
- });
-
testWidgets("WidgetsApp doesn't have dependency on MediaQuery", (WidgetTester tester) async {
int routeBuildCount = 0;