modal_bottom_action.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'package:flutter/material.dart';
  2. import 'package:sport/widgets/misc.dart';
  3. Future showActionDialog(BuildContext context, Map<String, Function> actions) {
  4. return showModalBottomSheet(
  5. context: context,
  6. isScrollControlled: true,
  7. shape: RoundedRectangleBorder(
  8. borderRadius: BorderRadius.vertical(top: Radius.circular(10))),
  9. builder: (BuildContext context) {
  10. final Decoration decoration = BoxDecoration(
  11. border: Border(
  12. bottom: Divider.createBorderSide(context),
  13. ),
  14. );
  15. return SingleChildScrollView(
  16. child: Padding(
  17. padding: const EdgeInsets.all(12.0),
  18. child: SafeArea(
  19. child: Column(children: <Widget>[
  20. Column(
  21. children: actions.keys
  22. .map(
  23. (key) => DecoratedBox(
  24. position: DecorationPosition.foreground,
  25. decoration: decoration,
  26. child: InkWell(
  27. onTap: () {
  28. actions[key]?.call();
  29. Navigator.pop(context);
  30. },
  31. child: Container(
  32. width: double.infinity,
  33. height: 50.0,
  34. child: Center(
  35. child: Text(
  36. "$key",
  37. style:
  38. Theme.of(context).textTheme.subtitle1!,
  39. strutStyle: fixedLine,
  40. )),
  41. ))),
  42. )
  43. .toList(),
  44. ),
  45. Padding(
  46. padding: const EdgeInsets.only(top: 16.0, bottom: 10.0),
  47. child: InkWell(
  48. onTap: () => Navigator.maybePop(context),
  49. child: Container(
  50. height: 44.0,
  51. decoration: BoxDecoration(
  52. shape: BoxShape.rectangle,
  53. borderRadius:
  54. BorderRadius.all(Radius.circular(50)),
  55. color: Color(0xfff1f1f1)),
  56. child: Center(
  57. child: Text(
  58. "取消",
  59. style: Theme.of(context).textTheme.subtitle1!,
  60. strutStyle: fixedLine,
  61. )),
  62. )),
  63. )
  64. ]),
  65. )),
  66. );
  67. });
  68. }