fix: use default value when MaterialLocalizations are not available
Showing
1 changed file
with
12 additions
and
13 deletions
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; | ||
40 | - switch (platform) { | ||
41 | - case TargetPlatform.iOS: | ||
42 | - return ''; | ||
43 | - case TargetPlatform.android: | ||
44 | - case TargetPlatform.fuchsia: | ||
45 | - assert(debugCheckHasMaterialLocalizations(context)); | 37 | + final platform = Theme.of(context)?.platform ?? defaultTargetPlatform; |
38 | + switch (platform) { | ||
39 | + case TargetPlatform.iOS: | ||
40 | + return ''; | ||
41 | + case TargetPlatform.android: | ||
42 | + case TargetPlatform.fuchsia: | ||
43 | + if (Localizations.of(context, MaterialLocalizations) != null) { | ||
46 | return MaterialLocalizations.of(context).dialogLabel; | 44 | return MaterialLocalizations.of(context).dialogLabel; |
47 | - break; | ||
48 | - } | ||
49 | - return null; | 45 | + } else { |
46 | + return DefaultMaterialLocalizations().dialogLabel; | ||
47 | + } | ||
50 | } | 48 | } |
49 | + return null; | ||
51 | } | 50 | } |
52 | 51 | ||
53 | @override | 52 | @override |
-
Please register or login to post a comment