bottom_sheet_helper.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import 'package:flutter/material.dart';
  2. import 'final_widget.dart';
  3. class BottomSheetHelper {
  4. static void show(BuildContext context, List<Widget>? menuList) {
  5. if (menuList == null || menuList.isEmpty) {
  6. return;
  7. }
  8. List<Widget> list = [];
  9. list.addAll(menuList);
  10. list.add(Container(
  11. color: O2UI.backgroundColor,
  12. height: 4,
  13. ));
  14. list.add(ListTile(
  15. onTap: () {Navigator.of(context).pop();},
  16. title: const Align(
  17. alignment: Alignment.center,
  18. child: Text('取消', style: O2UI.primaryTextStyle),
  19. ),
  20. ));
  21. showModalBottomSheet(
  22. context: context,
  23. builder: (context) {
  24. return Wrap(
  25. children: list,
  26. );
  27. });
  28. }
  29. static void showWithTopClose(BuildContext context, List<Widget>? menuList,
  30. {String? title}) {
  31. if (menuList == null || menuList.isEmpty) {
  32. return;
  33. }
  34. showModalBottomSheet(
  35. context: context,
  36. builder: (context) {
  37. return Column(
  38. children: <Widget>[
  39. ListTile(
  40. title: title != null
  41. ? Align(
  42. alignment: Alignment.center,
  43. child: Text(title, style: O2UI.primaryTextStyle),
  44. )
  45. : null,
  46. trailing: IconButton(
  47. icon: const Icon(Icons.close),
  48. onPressed: () {
  49. Navigator.of(context).pop();
  50. }),
  51. ),
  52. Container(
  53. color: O2UI.backgroundColor,
  54. height: 4,
  55. ),
  56. Expanded(
  57. child: SingleChildScrollView(
  58. child: Wrap(
  59. children: menuList,
  60. ),
  61. ),
  62. flex: 1,
  63. )
  64. ],
  65. );
  66. });
  67. }
  68. }