PopupMenuButton的分割线,一般不单独使用,可指定高度。

相关组件

Divider PopupMenuButton

PopupMenuDivider基本使用

【height】 : 高度 【double】
171.gif

  1. import 'package:flutter/material.dart';
  2. import '../../../dialogs/dialog_about.dart';
  3. class CustomPopupMenuDivider extends StatelessWidget {
  4. final map = {
  5. "关于": Icons.info_outline,
  6. "帮助": Icons.help_outline,
  7. "问题反馈": Icons.add_comment,
  8. };
  9. @override
  10. Widget build(BuildContext context) {
  11. return Container(
  12. child: Column(
  13. children: <Widget>[
  14. _buildPopupMenuButton(context),
  15. PopupMenuDivider(),
  16. ],
  17. ),
  18. );
  19. }
  20. PopupMenuButton<String> _buildPopupMenuButton(BuildContext context) {
  21. return PopupMenuButton<String>(
  22. itemBuilder: (context) => [
  23. ...buildItems().sublist(0, 2),
  24. PopupMenuDivider(),
  25. ...buildItems().sublist(2, 3)
  26. ],
  27. offset: Offset(0, 50),
  28. color: Color(0xffF4FFFA),
  29. elevation: 1,
  30. shape: RoundedRectangleBorder(
  31. borderRadius: BorderRadius.only(
  32. topLeft: Radius.circular(20),
  33. bottomRight: Radius.circular(20),
  34. topRight: Radius.circular(5),
  35. bottomLeft: Radius.circular(5),
  36. )),
  37. onSelected: (e) {
  38. print(e);
  39. if (e == '关于') {
  40. DialogAbout.show(context);
  41. }
  42. },
  43. onCanceled: () => print('onCanceled'),
  44. );
  45. }
  46. List<PopupMenuItem<String>> buildItems() {
  47. return map.keys
  48. .toList()
  49. .map((e) => PopupMenuItem<String>(
  50. value: e,
  51. child: Wrap(
  52. spacing: 10,
  53. children: <Widget>[
  54. Icon(
  55. map[e],
  56. color: Colors.blue,
  57. ),
  58. Text(e),
  59. ],
  60. )))
  61. .toList();
  62. }
  63. }