Home > OS >  Doesn't show Popup menu in flutter
Doesn't show Popup menu in flutter

Time:09-23

I want to open popup menu when I click mouse button, but it doesn't open popup menu, how to solve it ?

// Showing popup menu
void _showPopupMenu(WarehouseItemDetails itemDetails) {
 PopupMenuButton(
  itemBuilder: (_) {
    return [
      const PopupMenuItem(
        child: Text('Text 1')
      ),
      const PopupMenuItem(
        child: Text('Text 2')
      )
    ];
  }
 );
}

CodePudding user response:

EDIT:

You can wrap the widget you want it to appear in, in a GestureDetector and pass the TapDownDetails to the function example below:

GestureDetector(
  onTapDown: (TapDownDetails details) {
    showPopupMenu(details.globalPosition);
  },
  child: //... your widget here,
);

This is the showPopupMenu function you want to use for this:

void showPoputMenu(Offset offset) {
  double left = offset.dx;
  double top = ofset.dy;
  showMenu(
    context: context,
    position: RelativeRect.fromLTRB(left, top, 10, 10),
    items: [// ... your items here],
  );
}

You are not calling a function to show a popup menu, use this instead:

showMenu(
  context: context,
  position: RelativeRect.fromLTRB(10, 10, 10, 10), //here you can specify the location,
  items: [
    PopupMenuItem(
      value: 1
      child: Text("TEST"),
    ),
    // .... more popup items
  ],
)
  • Related