Showing
2 changed files
with
53 additions
and
0 deletions
| @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; | @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; | ||
| 4 | 4 | ||
| 5 | import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; | 5 | import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; |
| 6 | 6 | ||
| 7 | +import 'modals/floating_modal.dart'; | ||
| 7 | import 'modals/modal_complex_all.dart'; | 8 | import 'modals/modal_complex_all.dart'; |
| 8 | import 'modals/modal_fit.dart'; | 9 | import 'modals/modal_fit.dart'; |
| 9 | import 'modals/modal_inside_modal.dart'; | 10 | import 'modals/modal_inside_modal.dart'; |
| @@ -142,6 +143,13 @@ class _MyHomePageState extends State<MyHomePage> { | @@ -142,6 +143,13 @@ class _MyHomePageState extends State<MyHomePage> { | ||
| 142 | scrollController: scrollController), | 143 | scrollController: scrollController), |
| 143 | )), | 144 | )), |
| 144 | ListTile( | 145 | ListTile( |
| 146 | + title: Text('Float Modal'), | ||
| 147 | + onTap: () => showFloatingModalBottomSheet( | ||
| 148 | + context: context, | ||
| 149 | + builder: (context, scrollController) => | ||
| 150 | + ModalFit(scrollController: scrollController), | ||
| 151 | + )), | ||
| 152 | + ListTile( | ||
| 145 | title: Text('Cupertino Modal fit'), | 153 | title: Text('Cupertino Modal fit'), |
| 146 | onTap: () => showCupertinoModalBottomSheet( | 154 | onTap: () => showCupertinoModalBottomSheet( |
| 147 | expand: false, | 155 | expand: false, |
example/lib/modals/floating_modal.dart
0 → 100644
| 1 | +import 'dart:math'; | ||
| 2 | + | ||
| 3 | +import 'package:flutter/material.dart'; | ||
| 4 | +import 'package:flutter/services.dart'; | ||
| 5 | +import 'package:flutter/widgets.dart'; | ||
| 6 | +import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; | ||
| 7 | + | ||
| 8 | +class FloatingModal extends StatelessWidget { | ||
| 9 | + final Widget child; | ||
| 10 | + final Color backgroundColor; | ||
| 11 | + | ||
| 12 | + const FloatingModal({Key key, this.child, this.backgroundColor}) | ||
| 13 | + : super(key: key); | ||
| 14 | + | ||
| 15 | + @override | ||
| 16 | + Widget build(BuildContext context) { | ||
| 17 | + return SafeArea( | ||
| 18 | + child: Padding( | ||
| 19 | + padding: EdgeInsets.symmetric(horizontal: 20), | ||
| 20 | + child: Material( | ||
| 21 | + color: backgroundColor, | ||
| 22 | + clipBehavior: Clip.antiAlias, | ||
| 23 | + borderRadius: BorderRadius.circular(12), | ||
| 24 | + child: child, | ||
| 25 | + ), | ||
| 26 | + ), | ||
| 27 | + ); | ||
| 28 | + } | ||
| 29 | +} | ||
| 30 | + | ||
| 31 | +Future<T> showFloatingModalBottomSheet<T>({ | ||
| 32 | + @required BuildContext context, | ||
| 33 | + @required ScrollWidgetBuilder builder, | ||
| 34 | + Color backgroundColor, | ||
| 35 | +}) async { | ||
| 36 | + final result = await showCustomModalBottomSheet( | ||
| 37 | + context: context, | ||
| 38 | + builder: builder, | ||
| 39 | + containerWidget: (_, animation, child) => FloatingModal( | ||
| 40 | + child: child, | ||
| 41 | + ), | ||
| 42 | + expand: false); | ||
| 43 | + | ||
| 44 | + return result; | ||
| 45 | +} |
-
Please register or login to post a comment