Flutter之PopupMenuButton组件

/**
    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(child: Text("热度"), value: "hot",),
                  PopupMenuItem(child: Text("最新"), value: "new",),
                ];
              },
              onSelected: (String action) {
                switch (action) {
                  case "hot":
                    print("热度");
                    break;
                  case "new":
                    print("最新");
                    break;
                }
              },
              onCanceled: () {
                print("onCanceled");
              },
            ),
          ),
        ),

码云地址:https://gitee.com/xgljh/Flutter.git

你可能感兴趣的:(Flutter之PopupMenuButton组件)