tb2761

fix: assertion of missing MaterialLocalizations when using CupertinoApp

@@ -32,17 +32,22 @@ class _ModalBottomSheet<T> extends StatefulWidget { @@ -32,17 +32,22 @@ class _ModalBottomSheet<T> extends StatefulWidget {
32 } 32 }
33 33
34 class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { 34 class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
35 - String _getRouteLabel(MaterialLocalizations localizations) {  
36 - final platform = Theme.of(context).platform;  
37 - switch (platform) {  
38 - case TargetPlatform.iOS:  
39 - return '';  
40 - case TargetPlatform.android:  
41 - case TargetPlatform.fuchsia:  
42 - return localizations.dialogLabel;  
43 - break; 35 + String _getRouteLabel() {
  36 + if (Theme.of(context, shadowThemeOnly: true) == null) {
  37 + return '';
  38 + } else {
  39 + final platform = Theme.of(context).platform;
  40 + switch (platform) {
  41 + case TargetPlatform.iOS:
  42 + return '';
  43 + case TargetPlatform.android:
  44 + case TargetPlatform.fuchsia:
  45 + assert(debugCheckHasMaterialLocalizations(context));
  46 + return MaterialLocalizations.of(context).dialogLabel;
  47 + break;
  48 + }
  49 + return null;
44 } 50 }
45 - return null;  
46 } 51 }
47 52
48 @override 53 @override
@@ -64,9 +69,6 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { @@ -64,9 +69,6 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
64 @override 69 @override
65 Widget build(BuildContext context) { 70 Widget build(BuildContext context) {
66 assert(debugCheckHasMediaQuery(context)); 71 assert(debugCheckHasMediaQuery(context));
67 - assert(debugCheckHasMaterialLocalizations(context));  
68 - final localizations = MaterialLocalizations.of(context);  
69 - final routeLabel = _getRouteLabel(localizations);  
70 72
71 return AnimatedBuilder( 73 return AnimatedBuilder(
72 animation: widget.route._animationController, 74 animation: widget.route._animationController,
@@ -76,7 +78,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { @@ -76,7 +78,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
76 return Semantics( 78 return Semantics(
77 scopesRoute: true, 79 scopesRoute: true,
78 namesRoute: true, 80 namesRoute: true,
79 - label: routeLabel, 81 + label: _getRouteLabel(),
80 explicitChildNodes: true, 82 explicitChildNodes: true,
81 child: ModalBottomSheet( 83 child: ModalBottomSheet(
82 expanded: widget.route.expanded, 84 expanded: widget.route.expanded,
@@ -4,10 +4,15 @@ @@ -4,10 +4,15 @@
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 6
7 -import 'package:flutter/cupertino.dart'; 7 +import 'package:flutter/cupertino.dart' show CupertinoTheme;
8 import 'package:flutter/foundation.dart'; 8 import 'package:flutter/foundation.dart';
9 import 'package:flutter/gestures.dart'; 9 import 'package:flutter/gestures.dart';
10 -import 'package:flutter/material.dart'; 10 +import 'package:flutter/material.dart'
  11 + show
  12 + Colors,
  13 + Theme,
  14 + MaterialLocalizations,
  15 + debugCheckHasMaterialLocalizations;
11 import 'package:flutter/services.dart'; 16 import 'package:flutter/services.dart';
12 import 'package:flutter/widgets.dart'; 17 import 'package:flutter/widgets.dart';
13 18
@@ -78,7 +83,13 @@ Future<T> showCupertinoModalBottomSheet<T>({ @@ -78,7 +83,13 @@ Future<T> showCupertinoModalBottomSheet<T>({
78 assert(useRootNavigator != null); 83 assert(useRootNavigator != null);
79 assert(enableDrag != null); 84 assert(enableDrag != null);
80 assert(debugCheckHasMediaQuery(context)); 85 assert(debugCheckHasMediaQuery(context));
81 - assert(debugCheckHasMaterialLocalizations(context)); 86 + final isCupertinoApp = Theme.of(context, shadowThemeOnly: true) == null;
  87 + String barrierLabel = '';
  88 + if (!isCupertinoApp) {
  89 + assert(debugCheckHasMaterialLocalizations(context));
  90 + barrierLabel = MaterialLocalizations.of(context).modalBarrierDismissLabel;
  91 + }
  92 +
82 final result = await Navigator.of(context, rootNavigator: useRootNavigator) 93 final result = await Navigator.of(context, rootNavigator: useRootNavigator)
83 .push(CupertinoModalBottomSheetRoute<T>( 94 .push(CupertinoModalBottomSheetRoute<T>(
84 builder: builder, 95 builder: builder,
@@ -88,7 +99,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ @@ -88,7 +99,7 @@ Future<T> showCupertinoModalBottomSheet<T>({
88 ), 99 ),
89 secondAnimationController: secondAnimation, 100 secondAnimationController: secondAnimation,
90 expanded: expand, 101 expanded: expand,
91 - barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, 102 + barrierLabel: barrierLabel,
92 elevation: elevation, 103 elevation: elevation,
93 bounce: bounce, 104 bounce: bounce,
94 shape: shape, 105 shape: shape,
@@ -264,7 +275,13 @@ class CupertinoScaffold extends StatefulWidget { @@ -264,7 +275,13 @@ class CupertinoScaffold extends StatefulWidget {
264 assert(useRootNavigator != null); 275 assert(useRootNavigator != null);
265 assert(enableDrag != null); 276 assert(enableDrag != null);
266 assert(debugCheckHasMediaQuery(context)); 277 assert(debugCheckHasMediaQuery(context));
267 - assert(debugCheckHasMaterialLocalizations(context)); 278 + assert(debugCheckHasMediaQuery(context));
  279 + final isCupertinoApp = Theme.of(context, shadowThemeOnly: true) == null;
  280 + String barrierLabel = '';
  281 + if (!isCupertinoApp) {
  282 + assert(debugCheckHasMaterialLocalizations(context));
  283 + barrierLabel = MaterialLocalizations.of(context).modalBarrierDismissLabel;
  284 + }
268 final result = await Navigator.of(context, rootNavigator: useRootNavigator) 285 final result = await Navigator.of(context, rootNavigator: useRootNavigator)
269 .push(CupertinoModalBottomSheetRoute<T>( 286 .push(CupertinoModalBottomSheetRoute<T>(
270 builder: builder, 287 builder: builder,
@@ -274,7 +291,7 @@ class CupertinoScaffold extends StatefulWidget { @@ -274,7 +291,7 @@ class CupertinoScaffold extends StatefulWidget {
274 backgroundColor: backgroundColor, 291 backgroundColor: backgroundColor,
275 ), 292 ),
276 expanded: expand, 293 expanded: expand,
277 - barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, 294 + barrierLabel: barrierLabel,
278 bounce: bounce, 295 bounce: bounce,
279 isDismissible: isDismissible ?? expand == false ? true : false, 296 isDismissible: isDismissible ?? expand == false ? true : false,
280 modalBarrierColor: barrierColor ?? Colors.black12, 297 modalBarrierColor: barrierColor ?? Colors.black12,