Unverified Commit 2fccf4d4 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Remove MediaQuery from WidgetsApp (#119377)

* Remove MediaQuery from WidgetsApp

* more

* fix test

* more deprecation notices.
parent d4c74858
...@@ -176,6 +176,11 @@ class CupertinoApp extends StatefulWidget { ...@@ -176,6 +176,11 @@ class CupertinoApp extends StatefulWidget {
this.actions, this.actions,
this.restorationScopeId, this.restorationScopeId,
this.scrollBehavior, 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, this.useInheritedMediaQuery = false,
}) : routeInformationProvider = null, }) : routeInformationProvider = null,
routeInformationParser = null, routeInformationParser = null,
...@@ -212,6 +217,11 @@ class CupertinoApp extends StatefulWidget { ...@@ -212,6 +217,11 @@ class CupertinoApp extends StatefulWidget {
this.actions, this.actions,
this.restorationScopeId, this.restorationScopeId,
this.scrollBehavior, 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, this.useInheritedMediaQuery = false,
}) : assert(routerDelegate != null || routerConfig != null), }) : assert(routerDelegate != null || routerConfig != null),
navigatorObservers = null, navigatorObservers = null,
...@@ -408,6 +418,11 @@ class CupertinoApp extends StatefulWidget { ...@@ -408,6 +418,11 @@ class CupertinoApp extends StatefulWidget {
final ScrollBehavior? scrollBehavior; final ScrollBehavior? scrollBehavior;
/// {@macro flutter.widgets.widgetsApp.useInheritedMediaQuery} /// {@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; final bool useInheritedMediaQuery;
@override @override
...@@ -541,7 +556,6 @@ class _CupertinoAppState extends State<CupertinoApp> { ...@@ -541,7 +556,6 @@ class _CupertinoAppState extends State<CupertinoApp> {
shortcuts: widget.shortcuts, shortcuts: widget.shortcuts,
actions: widget.actions, actions: widget.actions,
restorationScopeId: widget.restorationScopeId, restorationScopeId: widget.restorationScopeId,
useInheritedMediaQuery: widget.useInheritedMediaQuery,
); );
} }
return WidgetsApp( return WidgetsApp(
...@@ -576,7 +590,6 @@ class _CupertinoAppState extends State<CupertinoApp> { ...@@ -576,7 +590,6 @@ class _CupertinoAppState extends State<CupertinoApp> {
shortcuts: widget.shortcuts, shortcuts: widget.shortcuts,
actions: widget.actions, actions: widget.actions,
restorationScopeId: widget.restorationScopeId, restorationScopeId: widget.restorationScopeId,
useInheritedMediaQuery: widget.useInheritedMediaQuery,
); );
} }
......
...@@ -241,6 +241,11 @@ class MaterialApp extends StatefulWidget { ...@@ -241,6 +241,11 @@ class MaterialApp extends StatefulWidget {
this.actions, this.actions,
this.restorationScopeId, this.restorationScopeId,
this.scrollBehavior, 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, this.useInheritedMediaQuery = false,
}) : routeInformationProvider = null, }) : routeInformationProvider = null,
routeInformationParser = null, routeInformationParser = null,
...@@ -285,6 +290,11 @@ class MaterialApp extends StatefulWidget { ...@@ -285,6 +290,11 @@ class MaterialApp extends StatefulWidget {
this.actions, this.actions,
this.restorationScopeId, this.restorationScopeId,
this.scrollBehavior, 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, this.useInheritedMediaQuery = false,
}) : assert(routerDelegate != null || routerConfig != null), }) : assert(routerDelegate != null || routerConfig != null),
navigatorObservers = null, navigatorObservers = null,
...@@ -733,6 +743,11 @@ class MaterialApp extends StatefulWidget { ...@@ -733,6 +743,11 @@ class MaterialApp extends StatefulWidget {
final bool debugShowMaterialGrid; final bool debugShowMaterialGrid;
/// {@macro flutter.widgets.widgetsApp.useInheritedMediaQuery} /// {@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; final bool useInheritedMediaQuery;
@override @override
...@@ -983,7 +998,6 @@ class _MaterialAppState extends State<MaterialApp> { ...@@ -983,7 +998,6 @@ class _MaterialAppState extends State<MaterialApp> {
shortcuts: widget.shortcuts, shortcuts: widget.shortcuts,
actions: widget.actions, actions: widget.actions,
restorationScopeId: widget.restorationScopeId, restorationScopeId: widget.restorationScopeId,
useInheritedMediaQuery: widget.useInheritedMediaQuery,
); );
} }
...@@ -1019,7 +1033,6 @@ class _MaterialAppState extends State<MaterialApp> { ...@@ -1019,7 +1033,6 @@ class _MaterialAppState extends State<MaterialApp> {
shortcuts: widget.shortcuts, shortcuts: widget.shortcuts,
actions: widget.actions, actions: widget.actions,
restorationScopeId: widget.restorationScopeId, restorationScopeId: widget.restorationScopeId,
useInheritedMediaQuery: widget.useInheritedMediaQuery,
); );
} }
......
...@@ -241,9 +241,6 @@ typedef InitialRouteListFactory = List<Route<dynamic>> Function(String initialRo ...@@ -241,9 +241,6 @@ typedef InitialRouteListFactory = List<Route<dynamic>> Function(String initialRo
/// It is used by both [MaterialApp] and [CupertinoApp] to implement base /// It is used by both [MaterialApp] and [CupertinoApp] to implement base
/// functionality for an app. /// 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 /// Find references to many of the widgets that [WidgetsApp] wraps in the "See
/// also" section. /// also" section.
/// ///
...@@ -343,6 +340,11 @@ class WidgetsApp extends StatefulWidget { ...@@ -343,6 +340,11 @@ class WidgetsApp extends StatefulWidget {
this.shortcuts, this.shortcuts,
this.actions, this.actions,
this.restorationScopeId, 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, this.useInheritedMediaQuery = false,
}) : assert( }) : assert(
home == null || home == null ||
...@@ -437,6 +439,11 @@ class WidgetsApp extends StatefulWidget { ...@@ -437,6 +439,11 @@ class WidgetsApp extends StatefulWidget {
this.shortcuts, this.shortcuts,
this.actions, this.actions,
this.restorationScopeId, 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, this.useInheritedMediaQuery = false,
}) : assert((){ }) : assert((){
if (routerConfig != null) { if (routerConfig != null) {
...@@ -1153,11 +1160,16 @@ class WidgetsApp extends StatefulWidget { ...@@ -1153,11 +1160,16 @@ class WidgetsApp extends StatefulWidget {
final String? restorationScopeId; final String? restorationScopeId;
/// {@template flutter.widgets.widgetsApp.useInheritedMediaQuery} /// {@template flutter.widgets.widgetsApp.useInheritedMediaQuery}
/// If true, an inherited MediaQuery will be used. If one is not available, /// Deprecated. This setting is not ignored.
/// or this is false, one will be built from the window.
/// ///
/// Cannot be null, defaults to false. /// The widget never introduces its own [MediaQuery]; the [View] widget takes
/// care of that.
/// {@endtemplate} /// {@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; final bool useInheritedMediaQuery;
/// If true, forces the performance overlay to be visible in all instances. /// If true, forces the performance overlay to be visible in all instances.
...@@ -1724,18 +1736,6 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver { ...@@ -1724,18 +1736,6 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
assert(_debugCheckLocalizations(appLocale)); 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( return RootRestorationScope(
restorationId: widget.restorationScopeId, restorationId: widget.restorationScopeId,
child: SharedAppData( child: SharedAppData(
...@@ -1754,7 +1754,11 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver { ...@@ -1754,7 +1754,11 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
policy: ReadingOrderTraversalPolicy(), policy: ReadingOrderTraversalPolicy(),
child: TapRegionSurface( child: TapRegionSurface(
child: ShortcutRegistrar( child: ShortcutRegistrar(
child: child, child: Localizations(
locale: appLocale,
delegates: _localizationsDelegates.toList(),
child: title,
),
), ),
), ),
), ),
......
...@@ -192,8 +192,6 @@ void main() { ...@@ -192,8 +192,6 @@ void main() {
' _LocalizationsScope-[GlobalKey#00000]\n' ' _LocalizationsScope-[GlobalKey#00000]\n'
' Semantics\n' ' Semantics\n'
' Localizations\n' ' Localizations\n'
' MediaQuery\n'
' _MediaQueryFromView\n'
' Semantics\n' ' Semantics\n'
' _FocusInheritedScope\n' ' _FocusInheritedScope\n'
' Focus\n' ' Focus\n'
......
...@@ -1530,70 +1530,70 @@ void main() { ...@@ -1530,70 +1530,70 @@ void main() {
expect(snackBarBottomLeft, equals(bottomNavigationBarTopLeft)); expect(snackBarBottomLeft, equals(bottomNavigationBarTopLeft));
}, },
); );
}
testWidgets( testWidgets(
'Padding of $behavior is not consumed by viewInsets', 'Padding of ${SnackBarBehavior.fixed} is not consumed by viewInsets',
(WidgetTester tester) async { (WidgetTester tester) async {
final Widget child = MaterialApp( final Widget child = MaterialApp(
home: Scaffold( home: Scaffold(
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
child: const Icon(Icons.send), child: const Icon(Icons.send),
onPressed: () {}, 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'),
);
},
),
), ),
); 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( await tester.pumpWidget(
MediaQuery( MediaQuery(
data: const MediaQueryData( data: const MediaQueryData(
padding: EdgeInsets.only(bottom: 20.0), padding: EdgeInsets.only(bottom: 20.0),
),
child: child,
), ),
); child: child,
await tester.tap(find.text('X')); ),
await tester.pumpAndSettle(); // Show snackbar );
final Offset initialBottomLeft = tester.getBottomLeft(find.byType(SnackBar)); await tester.tap(find.text('X'));
final Offset initialBottomRight = tester.getBottomRight(find.byType(SnackBar)); await tester.pumpAndSettle(); // Show snackbar
// Consume bottom padding - as if by the keyboard opening final Offset initialBottomLeft = tester.getBottomLeft(find.byType(SnackBar));
await tester.pumpWidget( final Offset initialBottomRight = tester.getBottomRight(find.byType(SnackBar));
MediaQuery( // Consume bottom padding - as if by the keyboard opening
data: const MediaQueryData( await tester.pumpWidget(
viewPadding: EdgeInsets.all(20), MediaQuery(
viewInsets: EdgeInsets.all(100), data: const MediaQueryData(
), viewPadding: EdgeInsets.all(20),
child: child, viewInsets: EdgeInsets.all(100),
), ),
); child: child,
await tester.tap(find.text('X')); ),
await tester.pumpAndSettle(); // Have the SnackBar fully animate out. );
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 finalBottomLeft = tester.getBottomLeft(find.byType(SnackBar));
final Offset finalBottomRight = tester.getBottomRight(find.byType(SnackBar)); final Offset finalBottomRight = tester.getBottomRight(find.byType(SnackBar));
expect(initialBottomLeft, finalBottomLeft); expect(initialBottomLeft, finalBottomLeft);
expect(initialBottomRight, finalBottomRight); expect(initialBottomRight, finalBottomRight);
}, },
); );
}
testWidgets( testWidgets(
'${SnackBarBehavior.fixed} should align SnackBar with the bottom of Scaffold ' '${SnackBarBehavior.fixed} should align SnackBar with the bottom of Scaffold '
......
...@@ -595,55 +595,6 @@ void main() { ...@@ -595,55 +595,6 @@ void main() {
expect(tester.takeException(), "Warning: This application's locale, C_UTF-8, is not supported by all of its localization delegates."); 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 { testWidgets("WidgetsApp doesn't have dependency on MediaQuery", (WidgetTester tester) async {
int routeBuildCount = 0; int routeBuildCount = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment