Jaime Blasco
Committed by GitHub

Merge pull request #14 from bierbaumtim/master

Expose Curve for animating the route and the modal
@@ -38,6 +38,7 @@ class ModalBottomSheet extends StatefulWidget { @@ -38,6 +38,7 @@ class ModalBottomSheet extends StatefulWidget {
38 const ModalBottomSheet({ 38 const ModalBottomSheet({
39 Key key, 39 Key key,
40 this.animationController, 40 this.animationController,
  41 + this.animationCurve,
41 this.enableDrag = true, 42 this.enableDrag = true,
42 this.containerBuilder, 43 this.containerBuilder,
43 this.bounce = true, 44 this.bounce = true,
@@ -58,6 +59,11 @@ class ModalBottomSheet extends StatefulWidget { @@ -58,6 +59,11 @@ class ModalBottomSheet extends StatefulWidget {
58 /// is not just a passive observer. 59 /// is not just a passive observer.
59 final AnimationController animationController; 60 final AnimationController animationController;
60 61
  62 + /// The curve used by the animation showing and dismissing the bottom sheet.
  63 + ///
  64 + /// If no curve is provided it falls back to `Curves.easeOutSine`.
  65 + final Curve animationCurve;
  66 +
61 /// Allows the bottom sheet to go beyond the top bound of the content, 67 /// Allows the bottom sheet to go beyond the top bound of the content,
62 /// but then bounce the content back to the edge of 68 /// but then bounce the content back to the edge of
63 /// the top bound. 69 /// the top bound.
@@ -276,7 +282,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> @@ -276,7 +282,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet>
276 Widget build(BuildContext context) { 282 Widget build(BuildContext context) {
277 final bounceAnimation = CurvedAnimation( 283 final bounceAnimation = CurvedAnimation(
278 parent: _bounceDragController, 284 parent: _bounceDragController,
279 - curve: Curves.easeOutSine, 285 + curve: widget.animationCurve ?? Curves.easeOutSine,
280 ); 286 );
281 287
282 var child = widget.builder(context, _scrollController); 288 var child = widget.builder(context, _scrollController);
@@ -17,6 +17,7 @@ class _ModalBottomSheet<T> extends StatefulWidget { @@ -17,6 +17,7 @@ class _ModalBottomSheet<T> extends StatefulWidget {
17 this.scrollController, 17 this.scrollController,
18 this.expanded = false, 18 this.expanded = false,
19 this.enableDrag = true, 19 this.enableDrag = true,
  20 + this.animationCurve,
20 }) : assert(expanded != null), 21 }) : assert(expanded != null),
21 assert(enableDrag != null), 22 assert(enableDrag != null),
22 super(key: key); 23 super(key: key);
@@ -26,6 +27,7 @@ class _ModalBottomSheet<T> extends StatefulWidget { @@ -26,6 +27,7 @@ class _ModalBottomSheet<T> extends StatefulWidget {
26 final bool bounce; 27 final bool bounce;
27 final bool enableDrag; 28 final bool enableDrag;
28 final AnimationController secondAnimationController; 29 final AnimationController secondAnimationController;
  30 + final Curve animationCurve;
29 final ScrollController scrollController; 31 final ScrollController scrollController;
30 32
31 @override 33 @override
@@ -97,6 +99,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> { @@ -97,6 +99,7 @@ class _ModalBottomSheetState<T> extends State<_ModalBottomSheet<T>> {
97 builder: widget.route.builder, 99 builder: widget.route.builder,
98 enableDrag: widget.enableDrag, 100 enableDrag: widget.enableDrag,
99 bounce: widget.bounce, 101 bounce: widget.bounce,
  102 + animationCurve: widget.animationCurve,
100 ), 103 ),
101 ); 104 );
102 }, 105 },
@@ -116,6 +119,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> { @@ -116,6 +119,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
116 this.enableDrag = true, 119 this.enableDrag = true,
117 @required this.expanded, 120 @required this.expanded,
118 this.bounce = false, 121 this.bounce = false,
  122 + this.animationCurve,
119 RouteSettings settings, 123 RouteSettings settings,
120 }) : assert(expanded != null), 124 }) : assert(expanded != null),
121 assert(isDismissible != null), 125 assert(isDismissible != null),
@@ -132,6 +136,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> { @@ -132,6 +136,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
132 final ScrollController scrollController; 136 final ScrollController scrollController;
133 137
134 final AnimationController secondAnimationController; 138 final AnimationController secondAnimationController;
  139 + final Curve animationCurve;
135 140
136 @override 141 @override
137 Duration get transitionDuration => _bottomSheetDuration; 142 Duration get transitionDuration => _bottomSheetDuration;
@@ -172,6 +177,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> { @@ -172,6 +177,7 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
172 scrollController: scrollController, 177 scrollController: scrollController,
173 bounce: bounce, 178 bounce: bounce,
174 enableDrag: enableDrag, 179 enableDrag: enableDrag,
  180 + animationCurve: animationCurve,
175 ), 181 ),
176 ); 182 );
177 return bottomSheet; 183 return bottomSheet;
@@ -195,8 +201,8 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> { @@ -195,8 +201,8 @@ class ModalBottomSheetRoute<T> extends PopupRoute<T> {
195 } 201 }
196 202
197 /// Shows a modal material design bottom sheet. 203 /// Shows a modal material design bottom sheet.
198 -Future<T> showCustomModalBottomSheet<T>(  
199 - {@required BuildContext context, 204 +Future<T> showCustomModalBottomSheet<T>({
  205 + @required BuildContext context,
200 @required ScrollWidgetBuilder builder, 206 @required ScrollWidgetBuilder builder,
201 @required WidgetWithChildBuilder containerWidget, 207 @required WidgetWithChildBuilder containerWidget,
202 Color backgroundColor, 208 Color backgroundColor,
@@ -207,10 +213,12 @@ Future<T> showCustomModalBottomSheet<T>( @@ -207,10 +213,12 @@ Future<T> showCustomModalBottomSheet<T>(
207 bool bounce = false, 213 bool bounce = false,
208 bool expand = false, 214 bool expand = false,
209 AnimationController secondAnimation, 215 AnimationController secondAnimation,
  216 + Curve animationCurve,
210 bool useRootNavigator = false, 217 bool useRootNavigator = false,
211 bool isDismissible = true, 218 bool isDismissible = true,
212 bool enableDrag = true, 219 bool enableDrag = true,
213 - ScrollController scrollController}) async { 220 + ScrollController scrollController,
  221 +}) async {
214 assert(context != null); 222 assert(context != null);
215 assert(builder != null); 223 assert(builder != null);
216 assert(containerWidget != null); 224 assert(containerWidget != null);
@@ -231,6 +239,7 @@ Future<T> showCustomModalBottomSheet<T>( @@ -231,6 +239,7 @@ Future<T> showCustomModalBottomSheet<T>(
231 isDismissible: isDismissible, 239 isDismissible: isDismissible,
232 modalBarrierColor: barrierColor, 240 modalBarrierColor: barrierColor,
233 enableDrag: enableDrag, 241 enableDrag: enableDrag,
  242 + animationCurve: animationCurve,
234 )); 243 ));
235 return result; 244 return result;
236 } 245 }
@@ -66,6 +66,7 @@ Future<T> showBarModalBottomSheet<T>({ @@ -66,6 +66,7 @@ Future<T> showBarModalBottomSheet<T>({
66 bool bounce = true, 66 bool bounce = true,
67 bool expand = false, 67 bool expand = false,
68 AnimationController secondAnimation, 68 AnimationController secondAnimation,
  69 + Curve animationCurve,
69 bool useRootNavigator = false, 70 bool useRootNavigator = false,
70 bool isDismissible = true, 71 bool isDismissible = true,
71 bool enableDrag = true, 72 bool enableDrag = true,
@@ -91,6 +92,7 @@ Future<T> showBarModalBottomSheet<T>({ @@ -91,6 +92,7 @@ Future<T> showBarModalBottomSheet<T>({
91 isDismissible: isDismissible, 92 isDismissible: isDismissible,
92 modalBarrierColor: barrierColor, 93 modalBarrierColor: barrierColor,
93 enableDrag: enableDrag, 94 enableDrag: enableDrag,
  95 + animationCurve: animationCurve,
94 )); 96 ));
95 return result; 97 return result;
96 } 98 }
@@ -72,6 +72,8 @@ Future<T> showCupertinoModalBottomSheet<T>({ @@ -72,6 +72,8 @@ Future<T> showCupertinoModalBottomSheet<T>({
72 Color barrierColor, 72 Color barrierColor,
73 bool expand = false, 73 bool expand = false,
74 AnimationController secondAnimation, 74 AnimationController secondAnimation,
  75 + Curve animationCurve,
  76 + Curve previousRouteAnimationCurve,
75 bool useRootNavigator = false, 77 bool useRootNavigator = false,
76 bool bounce = true, 78 bool bounce = true,
77 bool isDismissible, 79 bool isDismissible,
@@ -107,11 +109,15 @@ Future<T> showCupertinoModalBottomSheet<T>({ @@ -107,11 +109,15 @@ Future<T> showCupertinoModalBottomSheet<T>({
107 isDismissible: isDismissible ?? expand == false ? true : false, 109 isDismissible: isDismissible ?? expand == false ? true : false,
108 modalBarrierColor: barrierColor ?? Colors.black12, 110 modalBarrierColor: barrierColor ?? Colors.black12,
109 enableDrag: enableDrag, 111 enableDrag: enableDrag,
  112 + animationCurve: animationCurve,
  113 + previousRouteAnimationCurve: previousRouteAnimationCurve,
110 )); 114 ));
111 return result; 115 return result;
112 } 116 }
113 117
114 class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { 118 class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
  119 + final Curve previousRouteAnimationCurve;
  120 +
115 CupertinoModalBottomSheetRoute({ 121 CupertinoModalBottomSheetRoute({
116 ScrollWidgetBuilder builder, 122 ScrollWidgetBuilder builder,
117 WidgetWithChildBuilder containerBuilder, 123 WidgetWithChildBuilder containerBuilder,
@@ -120,12 +126,14 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { @@ -120,12 +126,14 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
120 ShapeBorder shape, 126 ShapeBorder shape,
121 Clip clipBehavior, 127 Clip clipBehavior,
122 AnimationController secondAnimationController, 128 AnimationController secondAnimationController,
  129 + Curve animationCurve,
123 Color modalBarrierColor, 130 Color modalBarrierColor,
124 bool bounce = true, 131 bool bounce = true,
125 bool isDismissible = true, 132 bool isDismissible = true,
126 bool enableDrag = true, 133 bool enableDrag = true,
127 @required bool expanded, 134 @required bool expanded,
128 RouteSettings settings, 135 RouteSettings settings,
  136 + this.previousRouteAnimationCurve,
129 }) : assert(expanded != null), 137 }) : assert(expanded != null),
130 assert(isDismissible != null), 138 assert(isDismissible != null),
131 assert(enableDrag != null), 139 assert(enableDrag != null),
@@ -140,6 +148,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { @@ -140,6 +148,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
140 enableDrag: enableDrag, 148 enableDrag: enableDrag,
141 expanded: expanded, 149 expanded: expanded,
142 settings: settings, 150 settings: settings,
  151 + animationCurve: animationCurve,
143 ); 152 );
144 153
145 @override 154 @override
@@ -172,18 +181,25 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { @@ -172,18 +181,25 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> {
172 Widget getPreviousRouteTransition(BuildContext context, 181 Widget getPreviousRouteTransition(BuildContext context,
173 Animation<double> secondaryAnimation, Widget child) { 182 Animation<double> secondaryAnimation, Widget child) {
174 return _CupertinoModalTransition( 183 return _CupertinoModalTransition(
175 - secondaryAnimation: secondaryAnimation, body: child); 184 + secondaryAnimation: secondaryAnimation,
  185 + body: child,
  186 + animationCurve: previousRouteAnimationCurve,
  187 + );
176 } 188 }
177 } 189 }
178 190
179 class _CupertinoModalTransition extends StatelessWidget { 191 class _CupertinoModalTransition extends StatelessWidget {
180 final Animation<double> secondaryAnimation; 192 final Animation<double> secondaryAnimation;
  193 + final Curve animationCurve;
181 194
182 final Widget body; 195 final Widget body;
183 196
184 - const _CupertinoModalTransition(  
185 - {Key key, @required this.secondaryAnimation, @required this.body})  
186 - : super(key: key); 197 + const _CupertinoModalTransition({
  198 + Key key,
  199 + @required this.secondaryAnimation,
  200 + @required this.body,
  201 + this.animationCurve,
  202 + }) : super(key: key);
187 203
188 @override 204 @override
189 Widget build(BuildContext context) { 205 Widget build(BuildContext context) {
@@ -196,7 +212,7 @@ class _CupertinoModalTransition extends StatelessWidget { @@ -196,7 +212,7 @@ class _CupertinoModalTransition extends StatelessWidget {
196 212
197 final curvedAnimation = CurvedAnimation( 213 final curvedAnimation = CurvedAnimation(
198 parent: secondaryAnimation, 214 parent: secondaryAnimation,
199 - curve: Curves.easeOut, 215 + curve: animationCurve ?? Curves.easeOut,
200 ); 216 );
201 217
202 return AnnotatedRegion<SystemUiOverlayStyle>( 218 return AnnotatedRegion<SystemUiOverlayStyle>(
@@ -261,6 +277,8 @@ class CupertinoScaffold extends StatefulWidget { @@ -261,6 +277,8 @@ class CupertinoScaffold extends StatefulWidget {
261 static Future<T> showCupertinoModalBottomSheet<T>({ 277 static Future<T> showCupertinoModalBottomSheet<T>({
262 @required BuildContext context, 278 @required BuildContext context,
263 @required ScrollWidgetBuilder builder, 279 @required ScrollWidgetBuilder builder,
  280 + Curve animationCurve,
  281 + Curve previousRouteAnimationCurve,
264 Color backgroundColor, 282 Color backgroundColor,
265 Color barrierColor, 283 Color barrierColor,
266 bool expand = false, 284 bool expand = false,
@@ -295,6 +313,8 @@ class CupertinoScaffold extends StatefulWidget { @@ -295,6 +313,8 @@ class CupertinoScaffold extends StatefulWidget {
295 isDismissible: isDismissible ?? expand == false ? true : false, 313 isDismissible: isDismissible ?? expand == false ? true : false,
296 modalBarrierColor: barrierColor ?? Colors.black12, 314 modalBarrierColor: barrierColor ?? Colors.black12,
297 enableDrag: enableDrag, 315 enableDrag: enableDrag,
  316 + animationCurve: animationCurve,
  317 + previousRouteAnimationCurve: previousRouteAnimationCurve,
298 )); 318 ));
299 return result; 319 return result;
300 } 320 }
@@ -14,6 +14,7 @@ Future<T> showMaterialModalBottomSheet<T>({ @@ -14,6 +14,7 @@ Future<T> showMaterialModalBottomSheet<T>({
14 bool bounce = false, 14 bool bounce = false,
15 bool expand = false, 15 bool expand = false,
16 AnimationController secondAnimation, 16 AnimationController secondAnimation,
  17 + Curve animationCurve,
17 bool useRootNavigator = false, 18 bool useRootNavigator = false,
18 bool isDismissible = true, 19 bool isDismissible = true,
19 bool enableDrag = true, 20 bool enableDrag = true,
@@ -44,6 +45,7 @@ Future<T> showMaterialModalBottomSheet<T>({ @@ -44,6 +45,7 @@ Future<T> showMaterialModalBottomSheet<T>({
44 isDismissible: isDismissible, 45 isDismissible: isDismissible,
45 modalBarrierColor: barrierColor, 46 modalBarrierColor: barrierColor,
46 enableDrag: enableDrag, 47 enableDrag: enableDrag,
  48 + animationCurve: animationCurve,
47 )); 49 ));
48 return result; 50 return result;
49 } 51 }