custom_pop_up_menu_fork 2.0.0 copy "custom_pop_up_menu_fork: ^2.0.0" to clipboard
custom_pop_up_menu_fork: ^2.0.0 copied to clipboard

Wrap a widget with CustomPopupMenu, Tap or Long Press this widget, a popup menu would display in a suitable position. fix for https://github.com/malikwang/custom_pop_up_menu

CustomPopupMenu #

Wrap a widget with CustomPopupMenu, Tap or Long Press this widget, a popup menu would display in a suitable position.

Features #

  • Gesture: Tap/Long Press
  • Fully customized menu: can set any style of menu, the common styles see: example/lib/main.dart. just impl the menuBuilder.
  • preset two style of menu: gridview, listview ,in dark and light mode.
  • Auto calculate the position of menu, also supports manual adjustment.
  • Fix the bug of can't hide menu in original lib.

Demo #

Using this package, you are free to build similar popup menu in WeChat.

preset style: #

  menuBuilder: (){
             // return _buildLongPressMenu(menuController);
              return GridViewPopMenuLight(menuItems: menuItems, dataObj: message.content,controller: menuController,);
            },

 menuBuilder: () => ListViewPopMenuLight(menuItems: menuItems, dataObj: "添加按钮", controller: _controller),

image-20230506153155200

image-20230506153310655

image-20230506151741109

image-20230506153505200

image-20230506152758820

QuickPopUpMenu: #

Recommend to use this api

 QuickPopUpMenu({Key? key,
     required this.child,
     required this.menuItems,
     required this.dataObj,
     this.darkMode,
     this.pressType,
     this.useGridView,
     this.showArrow,
   })

it's just a quick wrap:

  Widget build(BuildContext context) {
    return CustomPopupMenu(
      child: child,
      menuBuilder: (){
        if(useGridView??false){
          if(darkMode ??false){
            return GridViewPopMenu(menuItems: menuItems, dataObj: dataObj,controller: menuController,);
          }else{
            return GridViewPopMenuLight(menuItems: menuItems, dataObj: dataObj,controller: menuController,);
          }
        }else{
          if(darkMode ?? false){
            return ListViewPopMenu(menuItems: menuItems, dataObj: dataObj,controller: menuController,);
          }else{
            return ListViewPopMenuLight(menuItems: menuItems, dataObj: dataObj,controller: menuController,);
          }
        }
      },
      controller: menuController,
      barrierColor: Colors.transparent,
      showArrow: showArrow??false,
      pressType: pressType??PressType.singleClick,
      verticalMargin: 0,
    );
  }

usage sample: #

QuickPopUpMenu(
            child: Text(message.content),
            pressType: PressType.longPress,
            menuItems:menuItems,
            useGridView: true,
            dataObj: message.content,
          )

bug fix in original lib #

Can not close menu when call controller.hideMenu() when use the popmenu in listview/gridview/scorllview, because the controller changes when scoll/reuse the item.

so we have to pass the event throught different controller:

custom_pop_up_menu.dart

  _updateView() {
    //debugPrint("_updateView()--->_controller-"+_controller.toString()+"@"+_controller.hashCode.toString()
     //   +", widget.controller: "+ widget.controller.toString()+"@"+widget.controller.hashCode.toString());
//_updateView()--->_controller-Instance of 'CustomPopupMenuController'@968634764, widget.controller: Instance of 'CustomPopupMenuController'@1068823743
    if(widget.controller != null && widget.controller != _controller){

      if(!widget.controller!.hasListeners){
        debugPrint("_updateView()--->widget.controller!.addListener,pass the outer listener event to the inner listener");
        widget.controller!.addListener(() {
          _controller!.toggleMenu();
        });
      }

    }

    bool menuIsShowing = _controller?.menuIsShowing ?? false;
    widget.menuOnChange?.call(menuIsShowing);
    if (menuIsShowing) {
      _showMenu();
    } else {
      _hideMenu();
    }

  }
3
likes
100
pub points
74%
popularity

Publisher

verified publisherhss01248.tech

Wrap a widget with CustomPopupMenu, Tap or Long Press this widget, a popup menu would display in a suitable position. fix for https://github.com/malikwang/custom_pop_up_menu

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on custom_pop_up_menu_fork