Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

showMenu position Flutter

i have a GridView Widget that contain some GridTiles that are wrapped with GestureDetector trying to showUp a menu to delete the GridTile when i have longPress on it ,,, everything is fine except that i want that menu to be shown from the point that i have clicked into not at the top of the app


    showMenu(
            context: context,
            position: ..........,// Here i want the solution
            items: [
              PopupMenuItem(
                child: FlatButton.icon(
                  onPressed: () {
                    _notesProv.deleteNote(id);
                    Navigator.of(context).pop();
                  },
                  icon: Icon(
                    Icons.delete,
                    color: Colors.black,
                  ),
                  label: Text(
                    'delete note',
                    style: TextStyle(color: Colors.black),
                  ),
                ),
              ),
            ],
            color: Colors.green[100],
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(30),
            ));

like image 575
mostafa amr Avatar asked Jul 10 '26 03:07

mostafa amr


1 Answers

I hope this helps.

GestureDetector(
 onLongPressStart: (details) async{
  final offset = details.globalPosition;

  showMenu(
    context: context,
    position: RelativeRect.fromLTRB(
      offset.dx,
      offset.dy,
      MediaQuery.of(context).size.width - offset.dx,
      MediaQuery.of(context).size.height - offset.dy,
    ),
    items: [
      PopupMenuItem(
        child: Text("0"),
      ),

      PopupMenuItem(
        child: Text("1"),
      ),

      PopupMenuItem(
        child: Text("2"),
      ),

    ]
);

},
 child: FaIcon(
   AppIcons.ellipseFa,
   size: 22,
 ),
)

enter image description here enter image description here

like image 143
ibrahim Eltayfe Avatar answered Jul 14 '26 13:07

ibrahim Eltayfe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!