Showing
4 changed files
with
47 additions
and
11 deletions
| @@ -112,6 +112,7 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -112,6 +112,7 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 112 | child: SafeArea( | 112 | child: SafeArea( |
| 113 | bottom: false, | 113 | bottom: false, |
| 114 | child: Column( | 114 | child: Column( |
| 115 | + crossAxisAlignment: CrossAxisAlignment.stretch, | ||
| 115 | mainAxisSize: MainAxisSize.min, | 116 | mainAxisSize: MainAxisSize.min, |
| 116 | children: <Widget>[ | 117 | children: <Widget>[ |
| 117 | ListTile( | 118 | ListTile( |
| @@ -119,6 +120,7 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -119,6 +120,7 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 119 | onTap: () => Navigator.of(context).push( | 120 | onTap: () => Navigator.of(context).push( |
| 120 | MaterialWithModalsPageRoute( | 121 | MaterialWithModalsPageRoute( |
| 121 | builder: (context) => CupertinoSharePage()))), | 122 | builder: (context) => CupertinoSharePage()))), |
| 123 | + section('STYLES'), | ||
| 122 | ListTile( | 124 | ListTile( |
| 123 | title: Text('Material fit'), | 125 | title: Text('Material fit'), |
| 124 | onTap: () => showMaterialModalBottomSheet( | 126 | onTap: () => showMaterialModalBottomSheet( |
| @@ -164,6 +166,7 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -164,6 +166,7 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 164 | builder: (context, scrollController) => | 166 | builder: (context, scrollController) => |
| 165 | ModalFit(scrollController: scrollController), | 167 | ModalFit(scrollController: scrollController), |
| 166 | )), | 168 | )), |
| 169 | + section('COMPLEX CASES'), | ||
| 167 | ListTile( | 170 | ListTile( |
| 168 | title: Text('Cupertino Small Modal forced to expand'), | 171 | title: Text('Cupertino Small Modal forced to expand'), |
| 169 | onTap: () => showCupertinoModalBottomSheet( | 172 | onTap: () => showCupertinoModalBottomSheet( |
| @@ -174,6 +177,17 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -174,6 +177,17 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 174 | ModalFit(scrollController: scrollController), | 177 | ModalFit(scrollController: scrollController), |
| 175 | )), | 178 | )), |
| 176 | ListTile( | 179 | ListTile( |
| 180 | + title: Text('Reverse list'), | ||
| 181 | + onTap: () => showBarModalBottomSheet( | ||
| 182 | + expand: true, | ||
| 183 | + context: context, | ||
| 184 | + backgroundColor: Colors.transparent, | ||
| 185 | + builder: (context, scrollController) => | ||
| 186 | + ModalInsideModal( | ||
| 187 | + scrollController: scrollController, | ||
| 188 | + reverse: true), | ||
| 189 | + )), | ||
| 190 | + ListTile( | ||
| 177 | title: Text('Cupertino Modal inside modal'), | 191 | title: Text('Cupertino Modal inside modal'), |
| 178 | onTap: () => showCupertinoModalBottomSheet( | 192 | onTap: () => showCupertinoModalBottomSheet( |
| 179 | expand: true, | 193 | expand: true, |
| @@ -222,4 +236,13 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -222,4 +236,13 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 222 | ), | 236 | ), |
| 223 | ); | 237 | ); |
| 224 | } | 238 | } |
| 239 | + | ||
| 240 | + Widget section(String title) { | ||
| 241 | + return Padding( | ||
| 242 | + padding: EdgeInsets.fromLTRB(16, 20, 16, 8), | ||
| 243 | + child: Text( | ||
| 244 | + title, | ||
| 245 | + style: Theme.of(context).textTheme.caption, | ||
| 246 | + )); | ||
| 247 | + } | ||
| 225 | } | 248 | } |
| @@ -4,8 +4,10 @@ import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; | @@ -4,8 +4,10 @@ import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; | ||
| 4 | 4 | ||
| 5 | class ModalInsideModal extends StatelessWidget { | 5 | class ModalInsideModal extends StatelessWidget { |
| 6 | final ScrollController scrollController; | 6 | final ScrollController scrollController; |
| 7 | + final bool reverse; | ||
| 7 | 8 | ||
| 8 | - const ModalInsideModal({Key key, this.scrollController}) : super(key: key); | 9 | + const ModalInsideModal({Key key, this.scrollController, this.reverse = false}) |
| 10 | + : super(key: key); | ||
| 9 | 11 | ||
| 10 | @override | 12 | @override |
| 11 | Widget build(BuildContext context) { | 13 | Widget build(BuildContext context) { |
| @@ -16,6 +18,7 @@ class ModalInsideModal extends StatelessWidget { | @@ -16,6 +18,7 @@ class ModalInsideModal extends StatelessWidget { | ||
| 16 | child: SafeArea( | 18 | child: SafeArea( |
| 17 | bottom: false, | 19 | bottom: false, |
| 18 | child: ListView( | 20 | child: ListView( |
| 21 | + reverse: reverse, | ||
| 19 | shrinkWrap: true, | 22 | shrinkWrap: true, |
| 20 | controller: scrollController, | 23 | controller: scrollController, |
| 21 | physics: ClampingScrollPhysics(), | 24 | physics: ClampingScrollPhysics(), |
| @@ -24,7 +27,7 @@ class ModalInsideModal extends StatelessWidget { | @@ -24,7 +27,7 @@ class ModalInsideModal extends StatelessWidget { | ||
| 24 | tiles: List.generate( | 27 | tiles: List.generate( |
| 25 | 100, | 28 | 100, |
| 26 | (index) => ListTile( | 29 | (index) => ListTile( |
| 27 | - title: Text('Item'), | 30 | + title: Text('Item $index'), |
| 28 | onTap: () => showCupertinoModalBottomSheet( | 31 | onTap: () => showCupertinoModalBottomSheet( |
| 29 | expand: true, | 32 | expand: true, |
| 30 | isDismissible: false, | 33 | isDismissible: false, |
| @@ -32,7 +35,7 @@ class ModalInsideModal extends StatelessWidget { | @@ -32,7 +35,7 @@ class ModalInsideModal extends StatelessWidget { | ||
| 32 | backgroundColor: Colors.transparent, | 35 | backgroundColor: Colors.transparent, |
| 33 | builder: (context, scrollController) => | 36 | builder: (context, scrollController) => |
| 34 | ModalInsideModal( | 37 | ModalInsideModal( |
| 35 | - scrollController: scrollController), | 38 | + scrollController: scrollController, reverse: reverse), |
| 36 | )), | 39 | )), |
| 37 | )).toList(), | 40 | )).toList(), |
| 38 | ), | 41 | ), |
| @@ -106,7 +106,7 @@ packages: | @@ -106,7 +106,7 @@ packages: | ||
| 106 | path: ".." | 106 | path: ".." |
| 107 | relative: true | 107 | relative: true |
| 108 | source: path | 108 | source: path |
| 109 | - version: "0.1.5" | 109 | + version: "0.1.6" |
| 110 | path: | 110 | path: |
| 111 | dependency: transitive | 111 | dependency: transitive |
| 112 | description: | 112 | description: |
| @@ -69,6 +69,8 @@ class ModalBottomSheet extends StatefulWidget { | @@ -69,6 +69,8 @@ class ModalBottomSheet extends StatefulWidget { | ||
| 69 | /// the top bound. | 69 | /// the top bound. |
| 70 | final bool bounce; | 70 | final bool bounce; |
| 71 | 71 | ||
| 72 | + // Force the widget to fill the maximum size of the viewport | ||
| 73 | + // or if false it will fit to the content of the widget | ||
| 72 | final bool expanded; | 74 | final bool expanded; |
| 73 | 75 | ||
| 74 | final WidgetWithChildBuilder containerBuilder; | 76 | final WidgetWithChildBuilder containerBuilder; |
| @@ -242,9 +244,17 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | @@ -242,9 +244,17 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | ||
| 242 | DateTime _startTime; | 244 | DateTime _startTime; |
| 243 | 245 | ||
| 244 | void _handleScrollUpdate(ScrollNotification notification) { | 246 | void _handleScrollUpdate(ScrollNotification notification) { |
| 245 | - if (notification.metrics.pixels <= notification.metrics.minScrollExtent) { | ||
| 246 | - if (!_scrollController.hasClients) return; | ||
| 247 | 247 | ||
| 248 | + final scrollPosition = _scrollController.position; | ||
| 249 | + | ||
| 250 | + final isScrollReversed = scrollPosition.axisDirection == AxisDirection.down; | ||
| 251 | + final offset = isScrollReversed | ||
| 252 | + ? scrollPosition.pixels | ||
| 253 | + : scrollPosition.maxScrollExtent - scrollPosition.pixels; | ||
| 254 | + | ||
| 255 | + if (offset <= 0) { | ||
| 256 | + //Check if scrollController is used | ||
| 257 | + if (!_scrollController.hasClients) return; | ||
| 248 | // Check if listener is same from scrollController. | 258 | // Check if listener is same from scrollController. |
| 249 | // TODO: Improve the way it checks if it the same view controller | 259 | // TODO: Improve the way it checks if it the same view controller |
| 250 | // Use PrimaryScrollController | 260 | // Use PrimaryScrollController |
| @@ -264,12 +274,13 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | @@ -264,12 +274,13 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | ||
| 264 | _startTime = null; | 274 | _startTime = null; |
| 265 | return; | 275 | return; |
| 266 | } | 276 | } |
| 267 | - // Otherwise the calculate the velocity with a VelocityTracker | ||
| 268 | - DragUpdateDetails dragDetails; | ||
| 269 | - if (_velocityTracker == null) { | 277 | + |
| 278 | +// Otherwise the calculate the velocity with a VelocityTracker | ||
| 279 | + if (_velocityTracker == null) { | ||
| 270 | _velocityTracker = VelocityTracker(); | 280 | _velocityTracker = VelocityTracker(); |
| 271 | _startTime = DateTime.now(); | 281 | _startTime = DateTime.now(); |
| 272 | } | 282 | } |
| 283 | + DragUpdateDetails dragDetails; | ||
| 273 | if (notification is ScrollUpdateNotification) { | 284 | if (notification is ScrollUpdateNotification) { |
| 274 | dragDetails = notification.dragDetails; | 285 | dragDetails = notification.dragDetails; |
| 275 | } | 286 | } |
| @@ -278,8 +289,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | @@ -278,8 +289,7 @@ class _ModalBottomSheetState extends State<ModalBottomSheet> | ||
| 278 | } | 289 | } |
| 279 | if (dragDetails != null) { | 290 | if (dragDetails != null) { |
| 280 | final duration = _startTime.difference(DateTime.now()); | 291 | final duration = _startTime.difference(DateTime.now()); |
| 281 | - final offset = Offset(0, notification.metrics.pixels); | ||
| 282 | - _velocityTracker.addPosition(duration, offset); | 292 | + _velocityTracker.addPosition(duration, Offset(0, offset)); |
| 283 | _handleDragUpdate(dragDetails.primaryDelta); | 293 | _handleDragUpdate(dragDetails.primaryDelta); |
| 284 | } else if (isDragging) { | 294 | } else if (isDragging) { |
| 285 | final velocity = _velocityTracker.getVelocity().pixelsPerSecond.dy; | 295 | final velocity = _velocityTracker.getVelocity().pixelsPerSecond.dy; |
-
Please register or login to post a comment