Committed by
GitHub
Merge pull request #3 from rodineijf/master
add borderRadius parameter to showCupertinoModalBottomSheet
Showing
1 changed file
with
27 additions
and
6 deletions
| @@ -21,6 +21,8 @@ import '../bottom_sheet_route.dart'; | @@ -21,6 +21,8 @@ import '../bottom_sheet_route.dart'; | ||
| 21 | 21 | ||
| 22 | const double _behind_widget_visible_height = 10; | 22 | const double _behind_widget_visible_height = 10; |
| 23 | 23 | ||
| 24 | +const Radius _default_top_radius = Radius.circular(12); | ||
| 25 | + | ||
| 24 | /// Cupertino Bottom Sheet Container | 26 | /// Cupertino Bottom Sheet Container |
| 25 | /// | 27 | /// |
| 26 | /// Clip the child widget to rectangle with top rounded corners and adds | 28 | /// Clip the child widget to rectangle with top rounded corners and adds |
| @@ -29,16 +31,17 @@ const double _behind_widget_visible_height = 10; | @@ -29,16 +31,17 @@ const double _behind_widget_visible_height = 10; | ||
| 29 | class _CupertinoBottomSheetContainer extends StatelessWidget { | 31 | class _CupertinoBottomSheetContainer extends StatelessWidget { |
| 30 | final Widget child; | 32 | final Widget child; |
| 31 | final Color backgroundColor; | 33 | final Color backgroundColor; |
| 34 | + final Radius topRadius; | ||
| 32 | 35 | ||
| 33 | const _CupertinoBottomSheetContainer( | 36 | const _CupertinoBottomSheetContainer( |
| 34 | - {Key key, this.child, this.backgroundColor}) | 37 | + {Key key, this.child, this.backgroundColor, @required this.topRadius}) |
| 35 | : super(key: key); | 38 | : super(key: key); |
| 36 | 39 | ||
| 37 | @override | 40 | @override |
| 38 | Widget build(BuildContext context) { | 41 | Widget build(BuildContext context) { |
| 39 | final topSafeAreaPadding = MediaQuery.of(context).padding.top; | 42 | final topSafeAreaPadding = MediaQuery.of(context).padding.top; |
| 40 | final topPadding = _behind_widget_visible_height + topSafeAreaPadding; | 43 | final topPadding = _behind_widget_visible_height + topSafeAreaPadding; |
| 41 | - final radius = Radius.circular(12); | 44 | + |
| 42 | final shadow = | 45 | final shadow = |
| 43 | BoxShadow(blurRadius: 10, color: Colors.black12, spreadRadius: 5); | 46 | BoxShadow(blurRadius: 10, color: Colors.black12, spreadRadius: 5); |
| 44 | final _backgroundColor = | 47 | final _backgroundColor = |
| @@ -46,7 +49,7 @@ class _CupertinoBottomSheetContainer extends StatelessWidget { | @@ -46,7 +49,7 @@ class _CupertinoBottomSheetContainer extends StatelessWidget { | ||
| 46 | return Padding( | 49 | return Padding( |
| 47 | padding: EdgeInsets.only(top: topPadding), | 50 | padding: EdgeInsets.only(top: topPadding), |
| 48 | child: ClipRRect( | 51 | child: ClipRRect( |
| 49 | - borderRadius: BorderRadius.only(topLeft: radius, topRight: radius), | 52 | + borderRadius: BorderRadius.vertical(top: topRadius), |
| 50 | child: Container( | 53 | child: Container( |
| 51 | decoration: | 54 | decoration: |
| 52 | BoxDecoration(color: _backgroundColor, boxShadow: [shadow]), | 55 | BoxDecoration(color: _backgroundColor, boxShadow: [shadow]), |
| @@ -78,6 +81,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ | @@ -78,6 +81,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ | ||
| 78 | bool bounce = true, | 81 | bool bounce = true, |
| 79 | bool isDismissible, | 82 | bool isDismissible, |
| 80 | bool enableDrag = true, | 83 | bool enableDrag = true, |
| 84 | + Radius topRadius = _default_top_radius, | ||
| 81 | Duration duration, | 85 | Duration duration, |
| 82 | }) async { | 86 | }) async { |
| 83 | assert(context != null); | 87 | assert(context != null); |
| @@ -99,6 +103,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ | @@ -99,6 +103,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ | ||
| 99 | containerBuilder: (context, _, child) => _CupertinoBottomSheetContainer( | 103 | containerBuilder: (context, _, child) => _CupertinoBottomSheetContainer( |
| 100 | child: child, | 104 | child: child, |
| 101 | backgroundColor: backgroundColor, | 105 | backgroundColor: backgroundColor, |
| 106 | + topRadius: topRadius, | ||
| 102 | ), | 107 | ), |
| 103 | secondAnimationController: secondAnimation, | 108 | secondAnimationController: secondAnimation, |
| 104 | expanded: expand, | 109 | expanded: expand, |
| @@ -110,6 +115,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ | @@ -110,6 +115,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ | ||
| 110 | isDismissible: isDismissible ?? expand == false ? true : false, | 115 | isDismissible: isDismissible ?? expand == false ? true : false, |
| 111 | modalBarrierColor: barrierColor ?? Colors.black12, | 116 | modalBarrierColor: barrierColor ?? Colors.black12, |
| 112 | enableDrag: enableDrag, | 117 | enableDrag: enableDrag, |
| 118 | + topRadius: topRadius, | ||
| 113 | animationCurve: animationCurve, | 119 | animationCurve: animationCurve, |
| 114 | previousRouteAnimationCurve: previousRouteAnimationCurve, | 120 | previousRouteAnimationCurve: previousRouteAnimationCurve, |
| 115 | duration: duration, | 121 | duration: duration, |
| @@ -118,6 +124,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ | @@ -118,6 +124,7 @@ Future<T> showCupertinoModalBottomSheet<T>({ | ||
| 118 | } | 124 | } |
| 119 | 125 | ||
| 120 | class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { | 126 | class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { |
| 127 | + final Radius topRadius; | ||
| 121 | final Curve previousRouteAnimationCurve; | 128 | final Curve previousRouteAnimationCurve; |
| 122 | 129 | ||
| 123 | CupertinoModalBottomSheetRoute({ | 130 | CupertinoModalBottomSheetRoute({ |
| @@ -136,6 +143,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { | @@ -136,6 +143,7 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { | ||
| 136 | @required bool expanded, | 143 | @required bool expanded, |
| 137 | Duration duration, | 144 | Duration duration, |
| 138 | RouteSettings settings, | 145 | RouteSettings settings, |
| 146 | + this.topRadius = _default_top_radius, | ||
| 139 | this.previousRouteAnimationCurve, | 147 | this.previousRouteAnimationCurve, |
| 140 | }) : assert(expanded != null), | 148 | }) : assert(expanded != null), |
| 141 | assert(isDismissible != null), | 149 | assert(isDismissible != null), |
| @@ -188,12 +196,14 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { | @@ -188,12 +196,14 @@ class CupertinoModalBottomSheetRoute<T> extends ModalBottomSheetRoute<T> { | ||
| 188 | secondaryAnimation: secondaryAnimation, | 196 | secondaryAnimation: secondaryAnimation, |
| 189 | body: child, | 197 | body: child, |
| 190 | animationCurve: previousRouteAnimationCurve, | 198 | animationCurve: previousRouteAnimationCurve, |
| 199 | + topRadius: topRadius, | ||
| 191 | ); | 200 | ); |
| 192 | } | 201 | } |
| 193 | } | 202 | } |
| 194 | 203 | ||
| 195 | class _CupertinoModalTransition extends StatelessWidget { | 204 | class _CupertinoModalTransition extends StatelessWidget { |
| 196 | final Animation<double> secondaryAnimation; | 205 | final Animation<double> secondaryAnimation; |
| 206 | + final Radius topRadius; | ||
| 197 | final Curve animationCurve; | 207 | final Curve animationCurve; |
| 198 | 208 | ||
| 199 | final Widget body; | 209 | final Widget body; |
| @@ -202,6 +212,7 @@ class _CupertinoModalTransition extends StatelessWidget { | @@ -202,6 +212,7 @@ class _CupertinoModalTransition extends StatelessWidget { | ||
| 202 | Key key, | 212 | Key key, |
| 203 | @required this.secondaryAnimation, | 213 | @required this.secondaryAnimation, |
| 204 | @required this.body, | 214 | @required this.body, |
| 215 | + @required this.topRadius, | ||
| 205 | this.animationCurve, | 216 | this.animationCurve, |
| 206 | }) : super(key: key); | 217 | }) : super(key: key); |
| 207 | 218 | ||
| @@ -230,7 +241,7 @@ class _CupertinoModalTransition extends StatelessWidget { | @@ -230,7 +241,7 @@ class _CupertinoModalTransition extends StatelessWidget { | ||
| 230 | final scale = 1 - progress / 10; | 241 | final scale = 1 - progress / 10; |
| 231 | final radius = progress == 0 | 242 | final radius = progress == 0 |
| 232 | ? 0.0 | 243 | ? 0.0 |
| 233 | - : (1 - progress) * startRoundCorner + progress * 12; | 244 | + : (1 - progress) * startRoundCorner + progress * topRadius.x; |
| 234 | return Stack( | 245 | return Stack( |
| 235 | children: <Widget>[ | 246 | children: <Widget>[ |
| 236 | Container(color: Colors.black), | 247 | Container(color: Colors.black), |
| @@ -253,11 +264,13 @@ class _CupertinoModalTransition extends StatelessWidget { | @@ -253,11 +264,13 @@ class _CupertinoModalTransition extends StatelessWidget { | ||
| 253 | 264 | ||
| 254 | class _CupertinoScaffold extends InheritedWidget { | 265 | class _CupertinoScaffold extends InheritedWidget { |
| 255 | final AnimationController animation; | 266 | final AnimationController animation; |
| 267 | + final Radius topRadius; | ||
| 256 | 268 | ||
| 257 | @override | 269 | @override |
| 258 | final Widget child; | 270 | final Widget child; |
| 259 | 271 | ||
| 260 | - const _CupertinoScaffold({Key key, this.animation, this.child}) | 272 | + const _CupertinoScaffold( |
| 273 | + {Key key, this.animation, this.child, this.topRadius}) | ||
| 261 | : super(key: key, child: child); | 274 | : super(key: key, child: child); |
| 262 | 275 | ||
| 263 | @override | 276 | @override |
| @@ -272,8 +285,11 @@ class CupertinoScaffold extends StatefulWidget { | @@ -272,8 +285,11 @@ class CupertinoScaffold extends StatefulWidget { | ||
| 272 | context.dependOnInheritedWidgetOfExactType<_CupertinoScaffold>(); | 285 | context.dependOnInheritedWidgetOfExactType<_CupertinoScaffold>(); |
| 273 | 286 | ||
| 274 | final Widget body; | 287 | final Widget body; |
| 288 | + final Radius topRadius; | ||
| 275 | 289 | ||
| 276 | - const CupertinoScaffold({Key key, this.body}) : super(key: key); | 290 | + const CupertinoScaffold( |
| 291 | + {Key key, this.body, this.topRadius = _default_top_radius}) | ||
| 292 | + : super(key: key); | ||
| 277 | 293 | ||
| 278 | @override | 294 | @override |
| 279 | State<StatefulWidget> createState() => _CupertinoScaffoldState(); | 295 | State<StatefulWidget> createState() => _CupertinoScaffoldState(); |
| @@ -304,6 +320,7 @@ class CupertinoScaffold extends StatefulWidget { | @@ -304,6 +320,7 @@ class CupertinoScaffold extends StatefulWidget { | ||
| 304 | assert(debugCheckHasMaterialLocalizations(context)); | 320 | assert(debugCheckHasMaterialLocalizations(context)); |
| 305 | barrierLabel = MaterialLocalizations.of(context).modalBarrierDismissLabel; | 321 | barrierLabel = MaterialLocalizations.of(context).modalBarrierDismissLabel; |
| 306 | } | 322 | } |
| 323 | + final topRadius = CupertinoScaffold.of(context).topRadius; | ||
| 307 | final result = await Navigator.of(context, rootNavigator: useRootNavigator) | 324 | final result = await Navigator.of(context, rootNavigator: useRootNavigator) |
| 308 | .push(CupertinoModalBottomSheetRoute<T>( | 325 | .push(CupertinoModalBottomSheetRoute<T>( |
| 309 | builder: builder, | 326 | builder: builder, |
| @@ -311,6 +328,7 @@ class CupertinoScaffold extends StatefulWidget { | @@ -311,6 +328,7 @@ class CupertinoScaffold extends StatefulWidget { | ||
| 311 | containerBuilder: (context, _, child) => _CupertinoBottomSheetContainer( | 328 | containerBuilder: (context, _, child) => _CupertinoBottomSheetContainer( |
| 312 | child: child, | 329 | child: child, |
| 313 | backgroundColor: backgroundColor, | 330 | backgroundColor: backgroundColor, |
| 331 | + topRadius: topRadius, | ||
| 314 | ), | 332 | ), |
| 315 | expanded: expand, | 333 | expanded: expand, |
| 316 | barrierLabel: barrierLabel, | 334 | barrierLabel: barrierLabel, |
| @@ -318,6 +336,7 @@ class CupertinoScaffold extends StatefulWidget { | @@ -318,6 +336,7 @@ class CupertinoScaffold extends StatefulWidget { | ||
| 318 | isDismissible: isDismissible ?? expand == false ? true : false, | 336 | isDismissible: isDismissible ?? expand == false ? true : false, |
| 319 | modalBarrierColor: barrierColor ?? Colors.black12, | 337 | modalBarrierColor: barrierColor ?? Colors.black12, |
| 320 | enableDrag: enableDrag, | 338 | enableDrag: enableDrag, |
| 339 | + topRadius: topRadius, | ||
| 321 | animationCurve: animationCurve, | 340 | animationCurve: animationCurve, |
| 322 | previousRouteAnimationCurve: previousRouteAnimationCurve, | 341 | previousRouteAnimationCurve: previousRouteAnimationCurve, |
| 323 | duration: duration, | 342 | duration: duration, |
| @@ -348,9 +367,11 @@ class _CupertinoScaffoldState extends State<CupertinoScaffold> | @@ -348,9 +367,11 @@ class _CupertinoScaffoldState extends State<CupertinoScaffold> | ||
| 348 | Widget build(BuildContext context) { | 367 | Widget build(BuildContext context) { |
| 349 | return _CupertinoScaffold( | 368 | return _CupertinoScaffold( |
| 350 | animation: animationController, | 369 | animation: animationController, |
| 370 | + topRadius: widget.topRadius, | ||
| 351 | child: _CupertinoModalTransition( | 371 | child: _CupertinoModalTransition( |
| 352 | secondaryAnimation: animationController, | 372 | secondaryAnimation: animationController, |
| 353 | body: widget.body, | 373 | body: widget.body, |
| 374 | + topRadius: widget.topRadius, | ||
| 354 | ), | 375 | ), |
| 355 | ); | 376 | ); |
| 356 | } | 377 | } |
-
Please register or login to post a comment