flutter

Flutter之PopupMenuButton组件

2018-11-30  本文已影响144人  习惯了_就好
/**
    const PopupMenuButton({
    Key key,
    @required this.itemBuilder,
    this.initialValue,//初始值,如果itemBuilder里该值,则会高亮显示
    this.onSelected,//选中弹出弹出选项的回调
    this.onCanceled,//点屏幕外取消回调,点击屏幕其他地方时调用
    this.tooltip,//
    this.elevation = 8.0,//
    this.padding = const EdgeInsets.all(8.0),
    this.child,//修改PopupMenuButton默认三个点的图标为设置的child,不能与icon同时使用
    this.icon,//修改PopupMenuButton默认三个点的图标为设置的icon,不能与child同时使用
    this.offset = Offset.zero,
    })
 */
body: Container(
          child: Center(
            child: PopupMenuButton(
//              icon: Icon(Icons.home),
              child: Text("abc"),
              tooltip: "长按提示",
              initialValue: "hot",
              padding: EdgeInsets.all(0.0),
              itemBuilder: (BuildContext context) {
                return <PopupMenuItem<String>>[
                  PopupMenuItem<String>(child: Text("热度"), value: "hot",),
                  PopupMenuItem<String>(child: Text("最新"), value: "new",),
                ];
              },
              onSelected: (String action) {
                switch (action) {
                  case "hot":
                    print("热度");
                    break;
                  case "new":
                    print("最新");
                    break;
                }
              },
              onCanceled: () {
                print("onCanceled");
              },
            ),
          ),
        ),
上一篇下一篇

猜你喜欢

热点阅读