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 {
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 @@ class CupertinoApp extends StatefulWidget {
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 @@ class CupertinoApp extends StatefulWidget {
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 @@ class _CupertinoAppState extends State<CupertinoApp> {
shortcuts: widget.shortcuts,
actions: widget.actions,
restorationScopeId: widget.restorationScopeId,
useInheritedMediaQuery: widget.useInheritedMediaQuery,
);
}
return WidgetsApp(
......@@ -576,7 +590,6 @@ class _CupertinoAppState extends State<CupertinoApp> {
shortcuts: widget.shortcuts,
actions: widget.actions,
restorationScopeId: widget.restorationScopeId,
useInheritedMediaQuery: widget.useInheritedMediaQuery,
);
}
......
......@@ -241,6 +241,11 @@ class MaterialApp extends StatefulWidget {
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 @@ class MaterialApp extends StatefulWidget {
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 @@ class MaterialApp extends StatefulWidget {
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 @@ class _MaterialAppState extends State<MaterialApp> {
shortcuts: widget.shortcuts,
actions: widget.actions,
restorationScopeId: widget.restorationScopeId,
useInheritedMediaQuery: widget.useInheritedMediaQuery,
);
}
......@@ -1019,7 +1033,6 @@ class _MaterialAppState extends State<MaterialApp> {
shortcuts: widget.shortcuts,
actions: widget.actions,
restorationScopeId: widget.restorationScopeId,
useInheritedMediaQuery: widget.useInheritedMediaQuery,
);
}
......
......@@ -241,9 +241,6 @@ typedef InitialRouteListFactory = List<Route<dynamic>> Function(String initialRo
/// 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 @@ class WidgetsApp extends StatefulWidget {
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 @@ class WidgetsApp extends StatefulWidget {
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 @@ class WidgetsApp extends StatefulWidget {
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 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
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 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
policy: ReadingOrderTraversalPolicy(),
child: TapRegionSurface(
child: ShortcutRegistrar(
child: child,
child: Localizations(
locale: appLocale,
delegates: _localizationsDelegates.toList(),
child: title,
),
),
),
),
......
......@@ -192,8 +192,6 @@ void main() {
' _LocalizationsScope-[GlobalKey#00000]\n'
' Semantics\n'
' Localizations\n'
' MediaQuery\n'
' _MediaQueryFromView\n'
' Semantics\n'
' _FocusInheritedScope\n'
' Focus\n'
......
......@@ -1530,9 +1530,10 @@ void main() {
expect(snackBarBottomLeft, equals(bottomNavigationBarTopLeft));
},
);
}
testWidgets(
'Padding of $behavior is not consumed by viewInsets',
'Padding of ${SnackBarBehavior.fixed} is not consumed by viewInsets',
(WidgetTester tester) async {
final Widget child = MaterialApp(
home: Scaffold(
......@@ -1550,7 +1551,7 @@ void main() {
content: const Text('I am a snack bar.'),
duration: const Duration(seconds: 2),
action: SnackBarAction(label: 'ACTION', onPressed: () {}),
behavior: behavior,
behavior: SnackBarBehavior.fixed,
),
);
},
......@@ -1593,7 +1594,6 @@ void main() {
expect(initialBottomRight, finalBottomRight);
},
);
}
testWidgets(
'${SnackBarBehavior.fixed} should align SnackBar with the bottom of Scaffold '
......
......@@ -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.");
});
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;
......
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