modal_bottom_action.dart 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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(borderRadius: BorderRadius.vertical(top: Radius.circular(10))),
  8. builder: (BuildContext context) {
  9. final Decoration decoration = BoxDecoration(
  10. border: Border(
  11. bottom: Divider.createBorderSide(context),
  12. ),
  13. );
  14. return SingleChildScrollView(
  15. child: Padding(
  16. padding: const EdgeInsets.all(12.0),
  17. child: SafeArea(
  18. child: Column(children: <Widget>[
  19. Column(
  20. children: actions.keys
  21. .map(
  22. (key) => DecoratedBox(
  23. position: DecorationPosition.foreground,
  24. decoration: decoration,
  25. child: InkWell(
  26. onTap: () {
  27. actions[key].call();
  28. Navigator.pop(context);
  29. },
  30. child: Container(
  31. width: double.infinity,
  32. height: 50.0,
  33. child: Center(
  34. child: Text(
  35. "$key",
  36. style: Theme.of(context).textTheme.subtitle1,
  37. strutStyle: fixedLine,
  38. )),
  39. ))),
  40. )
  41. .toList(),
  42. ),
  43. Padding(
  44. padding: const EdgeInsets.only(top: 16.0, bottom: 10.0),
  45. child: InkWell(
  46. onTap: () => Navigator.maybePop(context),
  47. child: Container(
  48. height: 44.0,
  49. decoration: BoxDecoration(shape: BoxShape.rectangle, borderRadius: BorderRadius.all(Radius.circular(50)), color: Color(0xfff1f1f1)),
  50. child: Center(
  51. child: Text(
  52. "取消",
  53. style: Theme.of(context).textTheme.subtitle1,
  54. strutStyle: fixedLine,
  55. )),
  56. )),
  57. )
  58. ]),
  59. )),
  60. );
  61. });
  62. }