Committed by
GitHub
Merge pull request #57 from DenDos/master
Add closeProgressThreshold parameter
Showing
6 changed files
with
24 additions
and
1 deletions
@@ -52,6 +52,7 @@ showMaterialModalBottomSheet( | @@ -52,6 +52,7 @@ showMaterialModalBottomSheet( | ||
52 | |AnimationController secondAnimation| The `secondAnimation` parameter allows you to provide an animation controller that will be used to animate push/pop of the modal route. Using this param is advised against and will be probably removed in future versions | | 52 | |AnimationController secondAnimation| The `secondAnimation` parameter allows you to provide an animation controller that will be used to animate push/pop of the modal route. Using this param is advised against and will be probably removed in future versions | |
53 | |bool bounce = false| The `bounce` parameter specifies if the bottom sheet can go beyond the top boundary while dragging | | 53 | |bool bounce = false| The `bounce` parameter specifies if the bottom sheet can go beyond the top boundary while dragging | |
54 | |Duration duration = const Duration(milliseconds: 400)| The `duration` of modal opening | | 54 | |Duration duration = const Duration(milliseconds: 400)| The `duration` of modal opening | |
55 | +|double closeProgressThreshold = 0.6| The `closeProgressThreshold` specifies when the bottom sheet will be dismissed when user drags it. | | ||
55 | 56 | ||
56 | 57 | ||
57 | #### Material params | 58 | #### Material params |
@@ -42,6 +42,7 @@ class ModalBottomSheet extends StatefulWidget { | @@ -42,6 +42,7 @@ class ModalBottomSheet extends StatefulWidget { | ||
42 | /// Creates a bottom sheet. | 42 | /// Creates a bottom sheet. |
43 | const ModalBottomSheet({ | 43 | const ModalBottomSheet({ |
44 | Key key, | 44 | Key key, |
45 | + this.closeProgressThreshold, | ||
45 | this.animationController, | 46 | this.animationController, |
46 | this.animationCurve, | 47 | this.animationCurve, |
47 | this.enableDrag = true, | 48 | this.enableDrag = true, |
@@ -57,6 +58,10 @@ class ModalBottomSheet extends StatefulWidget { | @@ -57,6 +58,10 @@ class ModalBottomSheet extends StatefulWidget { | ||
57 | assert(builder != null), | 58 | assert(builder != null), |
58 | super(key: key); | 59 | super(key: key); |
59 | 60 | ||
61 | + /// The closeProgressThreshold parameter | ||
62 | + /// specifies when the bottom sheet will be dismissed when user drags it. | ||
63 | + final double closeProgressThreshold; | ||
64 | + | ||
60 | /// The animation controller that controls the bottom sheet's entrance and | 65 | /// The animation controller that controls the bottom sheet's entrance and |
61 | /// exit animations. | 66 | /// exit animations. |
62 | /// | 67 | /// |
@@ -152,7 +157,8 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | @@ -152,7 +157,8 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | ||
152 | widget.animationController.value < _willPopThreshold; | 157 | widget.animationController.value < _willPopThreshold; |
153 | 158 | ||
154 | bool get hasReachedCloseThreshold => | 159 | bool get hasReachedCloseThreshold => |
155 | - widget.animationController.value < _closeProgressThreshold; | 160 | + widget.animationController.value < |
161 | + (widget.closeProgressThreshold ?? _closeProgressThreshold); | ||
156 | 162 | ||
157 | void _close() { | 163 | void _close() { |
158 | isDragging = false; | 164 | isDragging = false; |
@@ -11,6 +11,7 @@ const Duration _bottomSheetDuration = Duration(milliseconds: 400); | @@ -11,6 +11,7 @@ const Duration _bottomSheetDuration = Duration(milliseconds: 400); | ||
11 | class _ModalBottomSheet<T> extends StatefulWidget { | 11 | class _ModalBottomSheet<T> extends StatefulWidget { |
12 | const _ModalBottomSheet({ | 12 | const _ModalBottomSheet({ |
13 | Key key, | 13 | Key key, |
14 | + this.closeProgressThreshold, | ||
14 | this.route, | 15 | this.route, |
15 | this.secondAnimationController, | 16 | this.secondAnimationController, |
16 | this.bounce = false, | 17 | this.bounce = false, |
@@ -22,6 +23,7 @@ class _ModalBottomSheet<T> extends StatefulWidget { | @@ -22,6 +23,7 @@ class _ModalBottomSheet<T> extends StatefulWidget { | ||
22 | assert(enableDrag != null), | 23 | assert(enableDrag != null), |
23 | super(key: key); | 24 | super(key: key); |
24 | 25 | ||
26 | + final double closeProgressThreshold; | ||
25 | final ModalBottomSheetRoute<T> route; | 27 | final ModalBottomSheetRoute<T> route; |
26 | final bool expanded; | 28 | final bool expanded; |
27 | final bool bounce; | 29 | final bool bounce; |
@@ -85,6 +87,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { | @@ -85,6 +87,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { | ||
85 | label: _getRouteLabel(), | 87 | label: _getRouteLabel(), |
86 | explicitChildNodes: true, | 88 | explicitChildNodes: true, |
87 | child: ModalBottomSheet( | 89 | child: ModalBottomSheet( |
90 | + closeProgressThreshold: widget.closeProgressThreshold, | ||
88 | expanded: widget.route.expanded, | 91 | expanded: widget.route.expanded, |
89 | containerBuilder: widget.route.containerBuilder, | 92 | containerBuilder: widget.route.containerBuilder, |
90 | animationController: widget.route._animationController, | 93 | animationController: widget.route._animationController, |
@@ -113,6 +116,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { | @@ -113,6 +116,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { | ||
113 | 116 | ||
114 | class ModalBottomSheetRoute<T> extends PopupRoute<T> { | 117 | class ModalBottomSheetRoute<T> extends PopupRoute<T> { |
115 | ModalBottomSheetRoute({ | 118 | ModalBottomSheetRoute({ |
119 | + this.closeProgressThreshold, | ||
116 | this.containerBuilder, | 120 | this.containerBuilder, |
117 | this.builder, | 121 | this.builder, |
118 | this.scrollController, | 122 | this.scrollController, |
@@ -131,6 +135,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> { | @@ -131,6 +135,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> { | ||
131 | assert(enableDrag != null), | 135 | assert(enableDrag != null), |
132 | super(settings: settings); | 136 | super(settings: settings); |
133 | 137 | ||
138 | + final double closeProgressThreshold; | ||
134 | final WidgetWithChildBuilder containerBuilder; | 139 | final WidgetWithChildBuilder containerBuilder; |
135 | final ScrollWidgetBuilder builder; | 140 | final ScrollWidgetBuilder builder; |
136 | final bool expanded; | 141 | final bool expanded; |
@@ -180,6 +185,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> { | @@ -180,6 +185,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> { | ||
180 | context: context, | 185 | context: context, |
181 | // removeTop: true, | 186 | // removeTop: true, |
182 | child: _ModalBottomSheet<T>( | 187 | child: _ModalBottomSheet<T>( |
188 | + closeProgressThreshold: closeProgressThreshold, | ||
183 | route: this, | 189 | route: this, |
184 | secondAnimationController: secondAnimationController, | 190 | secondAnimationController: secondAnimationController, |
185 | expanded: expanded, | 191 | expanded: expanded, |
@@ -75,6 +75,7 @@ Future<T> showBarModalBottomSheet<T>({ | @@ -75,6 +75,7 @@ Future<T> showBarModalBottomSheet<T>({ | ||
75 | Color backgroundColor, | 75 | Color backgroundColor, |
76 | double elevation, | 76 | double elevation, |
77 | ShapeBorder shape, | 77 | ShapeBorder shape, |
78 | + double closeProgressThreshold, | ||
78 | Clip clipBehavior, | 79 | Clip clipBehavior, |
79 | Color barrierColor = Colors.black87, | 80 | Color barrierColor = Colors.black87, |
80 | bool bounce = true, | 81 | bool bounce = true, |
@@ -99,6 +100,7 @@ Future<T> showBarModalBottomSheet<T>({ | @@ -99,6 +100,7 @@ Future<T> showBarModalBottomSheet<T>({ | ||
99 | .push(ModalBottomSheetRoute<T>( | 100 | .push(ModalBottomSheetRoute<T>( |
100 | builder: builder, | 101 | builder: builder, |
101 | bounce: bounce, | 102 | bounce: bounce, |
103 | + closeProgressThreshold: closeProgressThreshold, | ||
102 | containerBuilder: (_, __, child) => BarBottomSheet( | 104 | containerBuilder: (_, __, child) => BarBottomSheet( |
103 | child: child, | 105 | child: child, |
104 | control: topControl, | 106 | control: topControl, |
@@ -70,6 +70,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ | @@ -70,6 +70,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ | ||
70 | @required ScrollWidgetBuilder builder, | 70 | @required ScrollWidgetBuilder builder, |
71 | Color backgroundColor, | 71 | Color backgroundColor, |
72 | double elevation, | 72 | double elevation, |
73 | + double closeProgressThreshold, | ||
73 | ShapeBorder shape, | 74 | ShapeBorder shape, |
74 | Clip clipBehavior, | 75 | Clip clipBehavior, |
75 | Color barrierColor, | 76 | Color barrierColor, |
@@ -110,6 +111,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ | @@ -110,6 +111,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ | ||
110 | ), | 111 | ), |
111 | secondAnimationController: secondAnimation, | 112 | secondAnimationController: secondAnimation, |
112 | expanded: expand, | 113 | expanded: expand, |
114 | + closeProgressThreshold: closeProgressThreshold, | ||
113 | barrierLabel: barrierLabel, | 115 | barrierLabel: barrierLabel, |
114 | elevation: elevation, | 116 | elevation: elevation, |
115 | bounce: bounce, | 117 | bounce: bounce, |
@@ -139,6 +141,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { | @@ -139,6 +141,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { | ||
139 | CupertinoModalBottomSheetRoute({ | 141 | CupertinoModalBottomSheetRoute({ |
140 | ScrollWidgetBuilder builder, | 142 | ScrollWidgetBuilder builder, |
141 | WidgetWithChildBuilder containerBuilder, | 143 | WidgetWithChildBuilder containerBuilder, |
144 | + double closeProgressThreshold, | ||
142 | String barrierLabel, | 145 | String barrierLabel, |
143 | double elevation, | 146 | double elevation, |
144 | ShapeBorder shape, | 147 | ShapeBorder shape, |
@@ -160,6 +163,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { | @@ -160,6 +163,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { | ||
160 | assert(isDismissible != null), | 163 | assert(isDismissible != null), |
161 | assert(enableDrag != null), | 164 | assert(enableDrag != null), |
162 | super( | 165 | super( |
166 | + closeProgressThreshold: closeProgressThreshold, | ||
163 | scrollController: scrollController, | 167 | scrollController: scrollController, |
164 | containerBuilder: containerBuilder, | 168 | containerBuilder: containerBuilder, |
165 | builder: builder, | 169 | builder: builder, |
@@ -318,6 +322,7 @@ class CupertinoScaffold extends StatefulWidget { | @@ -318,6 +322,7 @@ class CupertinoScaffold extends StatefulWidget { | ||
318 | static Future<T> showCupertinoModalBottomSheet<T>({ | 322 | static Future<T> showCupertinoModalBottomSheet<T>({ |
319 | @required BuildContext context, | 323 | @required BuildContext context, |
320 | @required ScrollWidgetBuilder builder, | 324 | @required ScrollWidgetBuilder builder, |
325 | + double closeProgressThreshold, | ||
321 | Curve animationCurve, | 326 | Curve animationCurve, |
322 | Curve previousRouteAnimationCurve, | 327 | Curve previousRouteAnimationCurve, |
323 | Color backgroundColor, | 328 | Color backgroundColor, |
@@ -345,6 +350,7 @@ class CupertinoScaffold extends StatefulWidget { | @@ -345,6 +350,7 @@ class CupertinoScaffold extends StatefulWidget { | ||
345 | final topRadius = CupertinoScaffold.of(context).topRadius; | 350 | final topRadius = CupertinoScaffold.of(context).topRadius; |
346 | final result = await Navigator.of(context, rootNavigator: useRootNavigator) | 351 | final result = await Navigator.of(context, rootNavigator: useRootNavigator) |
347 | .push(CupertinoModalBottomSheetRoute<T>( | 352 | .push(CupertinoModalBottomSheetRoute<T>( |
353 | + closeProgressThreshold: closeProgressThreshold, | ||
348 | builder: builder, | 354 | builder: builder, |
349 | secondAnimationController: CupertinoScaffold.of(context).animation, | 355 | secondAnimationController: CupertinoScaffold.of(context).animation, |
350 | containerBuilder: (context, _, child) => _CupertinoBottomSheetContainer( | 356 | containerBuilder: (context, _, child) => _CupertinoBottomSheetContainer( |
@@ -6,6 +6,7 @@ import 'dart:async'; | @@ -6,6 +6,7 @@ import 'dart:async'; | ||
6 | Future<T> showMaterialModalBottomSheet<T>({ | 6 | Future<T> showMaterialModalBottomSheet<T>({ |
7 | @required BuildContext context, | 7 | @required BuildContext context, |
8 | @required ScrollWidgetBuilder builder, | 8 | @required ScrollWidgetBuilder builder, |
9 | + double closeProgressThreshold, | ||
9 | Color backgroundColor, | 10 | Color backgroundColor, |
10 | double elevation, | 11 | double elevation, |
11 | ShapeBorder shape, | 12 | ShapeBorder shape, |
@@ -31,6 +32,7 @@ Future<T> showMaterialModalBottomSheet<T>({ | @@ -31,6 +32,7 @@ Future<T> showMaterialModalBottomSheet<T>({ | ||
31 | final result = await Navigator.of(context, rootNavigator: useRootNavigator) | 32 | final result = await Navigator.of(context, rootNavigator: useRootNavigator) |
32 | .push(ModalBottomSheetRoute<T>( | 33 | .push(ModalBottomSheetRoute<T>( |
33 | builder: builder, | 34 | builder: builder, |
35 | + closeProgressThreshold: closeProgressThreshold, | ||
34 | containerBuilder: _materialContainerBuilder( | 36 | containerBuilder: _materialContainerBuilder( |
35 | context, | 37 | context, |
36 | backgroundColor: backgroundColor, | 38 | backgroundColor: backgroundColor, |
-
Please register or login to post a comment