Flutter PopupMenuDivider


简介

一个提供菜单栏弹出对话框中每一项的水平线

  • 配合 PopupMenuItem 和 PopupMenuButton 使用
  • PopupMenuDivider 可以调整高度,但无法调整颜色

基本用法

此widget通过调整Divider widget 来适应于弹出菜单中

  • 在 PopupMenuButton 中直接 PopupMenuDivider() 即可

实例演示

import 'package:flutter/material.dart';

class PopupMenuDividerDemo extends StatefulWidget {
  _PopupMenuDividerDemoState createState() => _PopupMenuDividerDemoState();
}

class _PopupMenuDividerDemoState extends State<PopupMenuDividerDemo> {
  void showInSnackBar(String value) {
    Scaffold.of(context)
        .showSnackBar( SnackBar(content:  Text('You selected: $value')));
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: ListTile(
          title: const Text('An item with a sectioned menu'),
          trailing: PopupMenuButton<String>(
              padding: EdgeInsets.zero,
              onSelected: showInSnackBar,
              itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
                    const PopupMenuItem<String>(
                        value: 'Preview',
                        child: ListTile(
                            leading: Icon(Icons.visibility),
                            title: Text('Preview'))),
                    const PopupMenuItem<String>(
                        value: 'Share',
                        child: ListTile(
                            leading: Icon(Icons.person_add),
                            title: Text('Share'))),
                    const PopupMenuItem<String>(
                        value: 'Get Link',
                        child: ListTile(
                            leading: Icon(Icons.link),
                            title: Text('Get link'))),
                    const PopupMenuDivider(),
                    const PopupMenuItem<String>(
                        value: 'Remove',
                        child: ListTile(
                            leading: Icon(Icons.delete), title: Text('Remove')))
                  ])),
    );
  }
}