Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 2fccf4d

Browse files
authored
Remove MediaQuery from WidgetsApp (#119377)
* Remove MediaQuery from WidgetsApp * more * fix test * more deprecation notices.
1 parent d4c7485 commit 2fccf4d

File tree

6 files changed

+110
-131
lines changed

6 files changed

+110
-131
lines changed

packages/flutter/lib/src/cupertino/app.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@ class CupertinoApp extends StatefulWidget {
176176
this.actions,
177177
this.restorationScopeId,
178178
this.scrollBehavior,
179+
@Deprecated(
180+
'Remove this parameter as it is now ignored. '
181+
'CupertinoApp never introduces its own MediaQuery; the View widget takes care of that. '
182+
'This feature was deprecated after v3.7.0-29.0.pre.'
183+
)
179184
this.useInheritedMediaQuery = false,
180185
}) : routeInformationProvider = null,
181186
routeInformationParser = null,
@@ -212,6 +217,11 @@ class CupertinoApp extends StatefulWidget {
212217
this.actions,
213218
this.restorationScopeId,
214219
this.scrollBehavior,
220+
@Deprecated(
221+
'Remove this parameter as it is now ignored. '
222+
'CupertinoApp never introduces its own MediaQuery; the View widget takes care of that. '
223+
'This feature was deprecated after v3.7.0-29.0.pre.'
224+
)
215225
this.useInheritedMediaQuery = false,
216226
}) : assert(routerDelegate != null || routerConfig != null),
217227
navigatorObservers = null,
@@ -408,6 +418,11 @@ class CupertinoApp extends StatefulWidget {
408418
final ScrollBehavior? scrollBehavior;
409419

410420
/// {@macro flutter.widgets.widgetsApp.useInheritedMediaQuery}
421+
@Deprecated(
422+
'This setting is now ignored. '
423+
'CupertinoApp never introduces its own MediaQuery; the View widget takes care of that. '
424+
'This feature was deprecated after v3.7.0-29.0.pre.'
425+
)
411426
final bool useInheritedMediaQuery;
412427

413428
@override
@@ -541,7 +556,6 @@ class _CupertinoAppState extends State<CupertinoApp> {
541556
shortcuts: widget.shortcuts,
542557
actions: widget.actions,
543558
restorationScopeId: widget.restorationScopeId,
544-
useInheritedMediaQuery: widget.useInheritedMediaQuery,
545559
);
546560
}
547561
return WidgetsApp(
@@ -576,7 +590,6 @@ class _CupertinoAppState extends State<CupertinoApp> {
576590
shortcuts: widget.shortcuts,
577591
actions: widget.actions,
578592
restorationScopeId: widget.restorationScopeId,
579-
useInheritedMediaQuery: widget.useInheritedMediaQuery,
580593
);
581594
}
582595

packages/flutter/lib/src/material/app.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ class MaterialApp extends StatefulWidget {
241241
this.actions,
242242
this.restorationScopeId,
243243
this.scrollBehavior,
244+
@Deprecated(
245+
'Remove this parameter as it is now ignored. '
246+
'MaterialApp never introduces its own MediaQuery; the View widget takes care of that. '
247+
'This feature was deprecated after v3.7.0-29.0.pre.'
248+
)
244249
this.useInheritedMediaQuery = false,
245250
}) : routeInformationProvider = null,
246251
routeInformationParser = null,
@@ -285,6 +290,11 @@ class MaterialApp extends StatefulWidget {
285290
this.actions,
286291
this.restorationScopeId,
287292
this.scrollBehavior,
293+
@Deprecated(
294+
'Remove this parameter as it is now ignored. '
295+
'MaterialApp never introduces its own MediaQuery; the View widget takes care of that. '
296+
'This feature was deprecated after v3.7.0-29.0.pre.'
297+
)
288298
this.useInheritedMediaQuery = false,
289299
}) : assert(routerDelegate != null || routerConfig != null),
290300
navigatorObservers = null,
@@ -733,6 +743,11 @@ class MaterialApp extends StatefulWidget {
733743
final bool debugShowMaterialGrid;
734744

735745
/// {@macro flutter.widgets.widgetsApp.useInheritedMediaQuery}
746+
@Deprecated(
747+
'This setting is now ignored. '
748+
'MaterialApp never introduces its own MediaQuery; the View widget takes care of that. '
749+
'This feature was deprecated after v3.7.0-29.0.pre.'
750+
)
736751
final bool useInheritedMediaQuery;
737752

738753
@override
@@ -983,7 +998,6 @@ class _MaterialAppState extends State<MaterialApp> {
983998
shortcuts: widget.shortcuts,
984999
actions: widget.actions,
9851000
restorationScopeId: widget.restorationScopeId,
986-
useInheritedMediaQuery: widget.useInheritedMediaQuery,
9871001
);
9881002
}
9891003

@@ -1019,7 +1033,6 @@ class _MaterialAppState extends State<MaterialApp> {
10191033
shortcuts: widget.shortcuts,
10201034
actions: widget.actions,
10211035
restorationScopeId: widget.restorationScopeId,
1022-
useInheritedMediaQuery: widget.useInheritedMediaQuery,
10231036
);
10241037
}
10251038

packages/flutter/lib/src/widgets/app.dart

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,6 @@ typedef InitialRouteListFactory = List<Route<dynamic>> Function(String initialRo
241241
/// It is used by both [MaterialApp] and [CupertinoApp] to implement base
242242
/// functionality for an app.
243243
///
244-
/// Builds a [MediaQuery] using [MediaQuery.fromWindow]. To use an inherited
245-
/// [MediaQuery] instead, set [useInheritedMediaQuery] to true.
246-
///
247244
/// Find references to many of the widgets that [WidgetsApp] wraps in the "See
248245
/// also" section.
249246
///
@@ -343,6 +340,11 @@ class WidgetsApp extends StatefulWidget {
343340
this.shortcuts,
344341
this.actions,
345342
this.restorationScopeId,
343+
@Deprecated(
344+
'Remove this parameter as it is now ignored. '
345+
'WidgetsApp never introduces its own MediaQuery; the View widget takes care of that. '
346+
'This feature was deprecated after v3.7.0-29.0.pre.'
347+
)
346348
this.useInheritedMediaQuery = false,
347349
}) : assert(
348350
home == null ||
@@ -437,6 +439,11 @@ class WidgetsApp extends StatefulWidget {
437439
this.shortcuts,
438440
this.actions,
439441
this.restorationScopeId,
442+
@Deprecated(
443+
'Remove this parameter as it is now ignored. '
444+
'WidgetsApp never introduces its own MediaQuery; the View widget takes care of that. '
445+
'This feature was deprecated after v3.7.0-29.0.pre.'
446+
)
440447
this.useInheritedMediaQuery = false,
441448
}) : assert((){
442449
if (routerConfig != null) {
@@ -1153,11 +1160,16 @@ class WidgetsApp extends StatefulWidget {
11531160
final String? restorationScopeId;
11541161

11551162
/// {@template flutter.widgets.widgetsApp.useInheritedMediaQuery}
1156-
/// If true, an inherited MediaQuery will be used. If one is not available,
1157-
/// or this is false, one will be built from the window.
1163+
/// Deprecated. This setting is not ignored.
11581164
///
1159-
/// Cannot be null, defaults to false.
1165+
/// The widget never introduces its own [MediaQuery]; the [View] widget takes
1166+
/// care of that.
11601167
/// {@endtemplate}
1168+
@Deprecated(
1169+
'This setting is now ignored. '
1170+
'WidgetsApp never introduces its own MediaQuery; the View widget takes care of that. '
1171+
'This feature was deprecated after v3.7.0-29.0.pre.'
1172+
)
11611173
final bool useInheritedMediaQuery;
11621174

11631175
/// If true, forces the performance overlay to be visible in all instances.
@@ -1724,18 +1736,6 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
17241736

17251737
assert(_debugCheckLocalizations(appLocale));
17261738

1727-
Widget child = Localizations(
1728-
locale: appLocale,
1729-
delegates: _localizationsDelegates.toList(),
1730-
child: title,
1731-
);
1732-
1733-
if (!widget.useInheritedMediaQuery || MediaQuery.maybeOf(context) == null) {
1734-
child = MediaQuery.fromWindow(
1735-
child: child,
1736-
);
1737-
}
1738-
17391739
return RootRestorationScope(
17401740
restorationId: widget.restorationScopeId,
17411741
child: SharedAppData(
@@ -1754,7 +1754,11 @@ class _WidgetsAppState extends State<WidgetsApp> with WidgetsBindingObserver {
17541754
policy: ReadingOrderTraversalPolicy(),
17551755
child: TapRegionSurface(
17561756
child: ShortcutRegistrar(
1757-
child: child,
1757+
child: Localizations(
1758+
locale: appLocale,
1759+
delegates: _localizationsDelegates.toList(),
1760+
child: title,
1761+
),
17581762
),
17591763
),
17601764
),

packages/flutter/test/material/debug_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ void main() {
192192
' _LocalizationsScope-[GlobalKey#00000]\n'
193193
' Semantics\n'
194194
' Localizations\n'
195-
' MediaQuery\n'
196-
' _MediaQueryFromView\n'
197195
' Semantics\n'
198196
' _FocusInheritedScope\n'
199197
' Focus\n'

packages/flutter/test/material/snack_bar_test.dart

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,70 +1530,70 @@ void main() {
15301530
expect(snackBarBottomLeft, equals(bottomNavigationBarTopLeft));
15311531
},
15321532
);
1533+
}
15331534

1534-
testWidgets(
1535-
'Padding of $behavior is not consumed by viewInsets',
1536-
(WidgetTester tester) async {
1537-
final Widget child = MaterialApp(
1538-
home: Scaffold(
1539-
resizeToAvoidBottomInset: false,
1540-
floatingActionButton: FloatingActionButton(
1541-
child: const Icon(Icons.send),
1542-
onPressed: () {},
1543-
),
1544-
body: Builder(
1545-
builder: (BuildContext context) {
1546-
return GestureDetector(
1547-
onTap: () {
1548-
ScaffoldMessenger.of(context).showSnackBar(
1549-
SnackBar(
1550-
content: const Text('I am a snack bar.'),
1551-
duration: const Duration(seconds: 2),
1552-
action: SnackBarAction(label: 'ACTION', onPressed: () {}),
1553-
behavior: behavior,
1554-
),
1555-
);
1556-
},
1557-
child: const Text('X'),
1558-
);
1559-
},
1560-
),
1535+
testWidgets(
1536+
'Padding of ${SnackBarBehavior.fixed} is not consumed by viewInsets',
1537+
(WidgetTester tester) async {
1538+
final Widget child = MaterialApp(
1539+
home: Scaffold(
1540+
resizeToAvoidBottomInset: false,
1541+
floatingActionButton: FloatingActionButton(
1542+
child: const Icon(Icons.send),
1543+
onPressed: () {},
15611544
),
1562-
);
1545+
body: Builder(
1546+
builder: (BuildContext context) {
1547+
return GestureDetector(
1548+
onTap: () {
1549+
ScaffoldMessenger.of(context).showSnackBar(
1550+
SnackBar(
1551+
content: const Text('I am a snack bar.'),
1552+
duration: const Duration(seconds: 2),
1553+
action: SnackBarAction(label: 'ACTION', onPressed: () {}),
1554+
behavior: SnackBarBehavior.fixed,
1555+
),
1556+
);
1557+
},
1558+
child: const Text('X'),
1559+
);
1560+
},
1561+
),
1562+
),
1563+
);
15631564

1564-
await tester.pumpWidget(
1565-
MediaQuery(
1566-
data: const MediaQueryData(
1567-
padding: EdgeInsets.only(bottom: 20.0),
1568-
),
1569-
child: child,
1565+
await tester.pumpWidget(
1566+
MediaQuery(
1567+
data: const MediaQueryData(
1568+
padding: EdgeInsets.only(bottom: 20.0),
15701569
),
1571-
);
1572-
await tester.tap(find.text('X'));
1573-
await tester.pumpAndSettle(); // Show snackbar
1574-
final Offset initialBottomLeft = tester.getBottomLeft(find.byType(SnackBar));
1575-
final Offset initialBottomRight = tester.getBottomRight(find.byType(SnackBar));
1576-
// Consume bottom padding - as if by the keyboard opening
1577-
await tester.pumpWidget(
1578-
MediaQuery(
1579-
data: const MediaQueryData(
1580-
viewPadding: EdgeInsets.all(20),
1581-
viewInsets: EdgeInsets.all(100),
1582-
),
1583-
child: child,
1570+
child: child,
1571+
),
1572+
);
1573+
await tester.tap(find.text('X'));
1574+
await tester.pumpAndSettle(); // Show snackbar
1575+
final Offset initialBottomLeft = tester.getBottomLeft(find.byType(SnackBar));
1576+
final Offset initialBottomRight = tester.getBottomRight(find.byType(SnackBar));
1577+
// Consume bottom padding - as if by the keyboard opening
1578+
await tester.pumpWidget(
1579+
MediaQuery(
1580+
data: const MediaQueryData(
1581+
viewPadding: EdgeInsets.all(20),
1582+
viewInsets: EdgeInsets.all(100),
15841583
),
1585-
);
1586-
await tester.tap(find.text('X'));
1587-
await tester.pumpAndSettle(); // Have the SnackBar fully animate out.
1584+
child: child,
1585+
),
1586+
);
1587+
await tester.tap(find.text('X'));
1588+
await tester.pumpAndSettle(); // Have the SnackBar fully animate out.
15881589

1589-
final Offset finalBottomLeft = tester.getBottomLeft(find.byType(SnackBar));
1590-
final Offset finalBottomRight = tester.getBottomRight(find.byType(SnackBar));
1590+
final Offset finalBottomLeft = tester.getBottomLeft(find.byType(SnackBar));
1591+
final Offset finalBottomRight = tester.getBottomRight(find.byType(SnackBar));
15911592

1592-
expect(initialBottomLeft, finalBottomLeft);
1593-
expect(initialBottomRight, finalBottomRight);
1594-
},
1595-
);
1596-
}
1593+
expect(initialBottomLeft, finalBottomLeft);
1594+
expect(initialBottomRight, finalBottomRight);
1595+
},
1596+
);
15971597

15981598
testWidgets(
15991599
'${SnackBarBehavior.fixed} should align SnackBar with the bottom of Scaffold '

packages/flutter/test/widgets/app_test.dart

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -595,55 +595,6 @@ void main() {
595595
expect(tester.takeException(), "Warning: This application's locale, C_UTF-8, is not supported by all of its localization delegates.");
596596
});
597597

598-
testWidgets('WidgetsApp creates a MediaQuery if `useInheritedMediaQuery` is set to false', (WidgetTester tester) async {
599-
late BuildContext capturedContext;
600-
await tester.pumpWidget(
601-
WidgetsApp(
602-
builder: (BuildContext context, Widget? child) {
603-
capturedContext = context;
604-
return const Placeholder();
605-
},
606-
color: const Color(0xFF123456),
607-
),
608-
);
609-
expect(MediaQuery.of(capturedContext), isNotNull);
610-
});
611-
612-
testWidgets('WidgetsApp does not create MediaQuery if `useInheritedMediaQuery` is set to true and one is available', (WidgetTester tester) async {
613-
late BuildContext capturedContext;
614-
final UniqueKey uniqueKey = UniqueKey();
615-
await tester.pumpWidget(
616-
MediaQuery(
617-
key: uniqueKey,
618-
data: const MediaQueryData(),
619-
child: WidgetsApp(
620-
useInheritedMediaQuery: true,
621-
builder: (BuildContext context, Widget? child) {
622-
capturedContext = context;
623-
return const Placeholder();
624-
},
625-
color: const Color(0xFF123456),
626-
),
627-
),
628-
);
629-
expect(capturedContext.dependOnInheritedWidgetOfExactType<MediaQuery>()?.key, uniqueKey);
630-
});
631-
632-
testWidgets('WidgetsApp does create a MediaQuery if `useInheritedMediaQuery` is set to true and none is available', (WidgetTester tester) async {
633-
late BuildContext capturedContext;
634-
await tester.pumpWidget(
635-
WidgetsApp(
636-
useInheritedMediaQuery: true,
637-
builder: (BuildContext context, Widget? child) {
638-
capturedContext = context;
639-
return const Placeholder();
640-
},
641-
color: const Color(0xFF123456),
642-
),
643-
);
644-
expect(MediaQuery.of(capturedContext), isNotNull);
645-
});
646-
647598
testWidgets("WidgetsApp doesn't have dependency on MediaQuery", (WidgetTester tester) async {
648599
int routeBuildCount = 0;
649600

0 commit comments

Comments
 (0)