Committed by
GitHub
Bugfixes for ScrollController and improve compatibly with CupertinoApp/WidgetsApp
Merge pull request #7 from bierbaumtim/master Bugfixes for ScrollController and improvements to compatibly with CupertinoApp/WidgetsApp
Showing
5 changed files
with
36 additions
and
15 deletions
@@ -4,4 +4,6 @@ | @@ -4,4 +4,6 @@ | ||
4 | 4 | ||
5 | ## [0.1.4] - Clean code and fix small bugs | 5 | ## [0.1.4] - Clean code and fix small bugs |
6 | 6 | ||
7 | - | 7 | +## [0.1.5] - Bugfixes |
8 | +- fix assertion in CupertinoBottomSheet and BottomSheetRoute when using the CupetinoApp or WidgetsApp as root | ||
9 | +- fix assertion when scrollController isn't used by the builder |
@@ -231,6 +231,8 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | @@ -231,6 +231,8 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | ||
231 | void _handleScrollUpdate(ScrollNotification notification) { | 231 | void _handleScrollUpdate(ScrollNotification notification) { |
232 | if (notification.metrics.pixels <= notification.metrics.minScrollExtent) { | 232 | if (notification.metrics.pixels <= notification.metrics.minScrollExtent) { |
233 | //Check if listener is same from scrollController | 233 | //Check if listener is same from scrollController |
234 | + if (!_scrollController.hasClients) return; | ||
235 | + | ||
234 | if (_scrollController.position.pixels != notification.metrics.pixels) { | 236 | if (_scrollController.position.pixels != notification.metrics.pixels) { |
235 | return; | 237 | return; |
236 | } | 238 | } |
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'; |
@@ -32,15 +33,18 @@ class _ModalBottomSheet<T> extends StatefulWidget { | @@ -32,15 +33,18 @@ class _ModalBottomSheet<T> extends StatefulWidget { | ||
32 | } | 33 | } |
33 | 34 | ||
34 | class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { | 35 | class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { |
35 | - String _getRouteLabel(MaterialLocalizations localizations) { | ||
36 | - final platform = Theme.of(context).platform; | 36 | + String _getRouteLabel() { |
37 | + final platform = Theme.of(context)?.platform ?? defaultTargetPlatform; | ||
37 | switch (platform) { | 38 | switch (platform) { |
38 | case TargetPlatform.iOS: | 39 | case TargetPlatform.iOS: |
39 | return ''; | 40 | return ''; |
40 | case TargetPlatform.android: | 41 | case TargetPlatform.android: |
41 | case TargetPlatform.fuchsia: | 42 | case TargetPlatform.fuchsia: |
42 | - return localizations.dialogLabel; | ||
43 | - break; | 43 | + if (Localizations.of(context, MaterialLocalizations) != null) { |
44 | + return MaterialLocalizations.of(context).dialogLabel; | ||
45 | + } else { | ||
46 | + return DefaultMaterialLocalizations().dialogLabel; | ||
47 | + } | ||
44 | } | 48 | } |
45 | return null; | 49 | return null; |
46 | } | 50 | } |
@@ -64,9 +68,6 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { | @@ -64,9 +68,6 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { | ||
64 | @override | 68 | @override |
65 | Widget build(BuildContext context) { | 69 | Widget build(BuildContext context) { |
66 | assert(debugCheckHasMediaQuery(context)); | 70 | assert(debugCheckHasMediaQuery(context)); |
67 | - assert(debugCheckHasMaterialLocalizations(context)); | ||
68 | - final localizations = MaterialLocalizations.of(context); | ||
69 | - final routeLabel = _getRouteLabel(localizations); | ||
70 | 71 | ||
71 | return AnimatedBuilder( | 72 | return AnimatedBuilder( |
72 | animation: widget.route._animationController, | 73 | animation: widget.route._animationController, |
@@ -76,7 +77,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { | @@ -76,7 +77,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { | ||
76 | return Semantics( | 77 | return Semantics( |
77 | scopesRoute: true, | 78 | scopesRoute: true, |
78 | namesRoute: true, | 79 | namesRoute: true, |
79 | - label: routeLabel, | 80 | + label: _getRouteLabel(), |
80 | explicitChildNodes: true, | 81 | explicitChildNodes: true, |
81 | child: ModalBottomSheet( | 82 | child: ModalBottomSheet( |
82 | expanded: widget.route.expanded, | 83 | 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 hasMaterialLocalizations = |
87 | + Localizations.of<MaterialLocalizations>(context, MaterialLocalizations) != | ||
88 | + null; | ||
89 | + final barrierLabel = hasMaterialLocalizations | ||
90 | + ? 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,12 @@ class CupertinoScaffold extends StatefulWidget { | @@ -264,7 +275,12 @@ 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)); |
278 | + final isCupertinoApp = Theme.of(context, shadowThemeOnly: true) == null; | ||
279 | + String barrierLabel = ''; | ||
280 | + if (!isCupertinoApp) { | ||
267 | assert(debugCheckHasMaterialLocalizations(context)); | 281 | assert(debugCheckHasMaterialLocalizations(context)); |
282 | + barrierLabel = MaterialLocalizations.of(context).modalBarrierDismissLabel; | ||
283 | + } | ||
268 | final result = await Navigator.of(context, rootNavigator: useRootNavigator) | 284 | final result = await Navigator.of(context, rootNavigator: useRootNavigator) |
269 | .push(CupertinoModalBottomSheetRoute<T>( | 285 | .push(CupertinoModalBottomSheetRoute<T>( |
270 | builder: builder, | 286 | builder: builder, |
@@ -274,7 +290,7 @@ class CupertinoScaffold extends StatefulWidget { | @@ -274,7 +290,7 @@ class CupertinoScaffold extends StatefulWidget { | ||
274 | backgroundColor: backgroundColor, | 290 | backgroundColor: backgroundColor, |
275 | ), | 291 | ), |
276 | expanded: expand, | 292 | expanded: expand, |
277 | - barrierLabel: MaterialLocalizations.of(context).modalBarrierDismissLabel, | 293 | + barrierLabel: barrierLabel, |
278 | bounce: bounce, | 294 | bounce: bounce, |
279 | isDismissible: isDismissible ?? expand == false ? true : false, | 295 | isDismissible: isDismissible ?? expand == false ? true : false, |
280 | modalBarrierColor: barrierColor ?? Colors.black12, | 296 | modalBarrierColor: barrierColor ?? Colors.black12, |
1 | name: modal_bottom_sheet | 1 | name: modal_bottom_sheet |
2 | description: 'Create awesome and powerful modal bottom sheets. Material, Cupertino or create your own' | 2 | description: 'Create awesome and powerful modal bottom sheets. Material, Cupertino or create your own' |
3 | -version: 0.1.4 | 3 | +version: 0.1.5 |
4 | homepage: 'https://github.com/jamesblasco/modal_bottom_sheet' | 4 | homepage: 'https://github.com/jamesblasco/modal_bottom_sheet' |
5 | 5 | ||
6 | environment: | 6 | environment: |
-
Please register or login to post a comment