forked from firka/flutter
Remove MediaQuery from WidgetsApp (#119377)
* Remove MediaQuery from WidgetsApp * more * fix test * more deprecation notices.
This commit is contained in:
committed by
GitHub
parent
d4c74858fd
commit
2fccf4d471
@@ -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,71 +1530,71 @@ void main() {
|
||||
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',
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user