tb2761

fix: use default value when MaterialLocalizations are not available

1 import 'dart:async'; 1 import 'dart:async';
2 2
3 import 'package:flutter/cupertino.dart'; 3 import 'package:flutter/cupertino.dart';
  4 +import 'package:flutter/foundation.dart';
4 import 'package:flutter/material.dart'; 5 import 'package:flutter/material.dart';
5 6
6 import '../modal_bottom_sheet.dart'; 7 import '../modal_bottom_sheet.dart';
@@ -33,21 +34,19 @@ class _ModalBottomSheet<T> extends StatefulWidget { @@ -33,21 +34,19 @@ class _ModalBottomSheet<T> extends StatefulWidget {
33 34
34 class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { 35 class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
35 String _getRouteLabel() { 36 String _getRouteLabel() {
36 - if (Theme.of(context, shadowThemeOnly: true) == null) {  
37 - return '';  
38 - } else {  
39 - final platform = Theme.of(context).platform; 37 + final platform = Theme.of(context)?.platform ?? defaultTargetPlatform;
40 switch (platform) { 38 switch (platform) {
41 case TargetPlatform.iOS: 39 case TargetPlatform.iOS:
42 return ''; 40 return '';
43 case TargetPlatform.android: 41 case TargetPlatform.android:
44 case TargetPlatform.fuchsia: 42 case TargetPlatform.fuchsia:
45 - assert(debugCheckHasMaterialLocalizations(context)); 43 + if (Localizations.of(context, MaterialLocalizations) != null) {
46 return MaterialLocalizations.of(context).dialogLabel; 44 return MaterialLocalizations.of(context).dialogLabel;
47 - break; 45 + } else {
  46 + return DefaultMaterialLocalizations().dialogLabel;
48 } 47 }
49 - return null;  
50 } 48 }
  49 + return null;
51 } 50 }
52 51
53 @override 52 @override