How to create a pop up menu on a ListTile?? Why is my code for it not working??

1,335 views
Skip to first unread message

Faraz Khan

unread,
Jul 30, 2020, 8:15:47 PM7/30/20
to Flutter Development (flutter-dev)
Hi,

I've been struggling for the past hour trying to create a popup menu at the location of my ListTile item.

I have a ListTile and on longpress() I want to open a popup menu with options to either open it or delete it. I wrote the following within the onLongPressed() of this listTile, but nothing opens.. The popup menu does not show..

What am I doing wrong?

onLongPress: () {
PopupMenuButton<String>(
onSelected: (String value) {
setState(() {

});
},
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
const PopupMenuItem<String>(
value: 'Open',
child: Text('Open'),
),
const PopupMenuItem<String>(
value: 'Delete',
child: Text('Delete'),
),
],
);
},

Suzuki Tomohiro

unread,
Jul 30, 2020, 8:29:06 PM7/30/20
to Faraz Khan, Flutter Development (flutter-dev)
Your inLongPress function creates PopupMenuButton instance and does not use it. You have to add the PopupMenuButton into your widget tree. I think you want to read document of PopupMenuButton on how to use it.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/995d6c42-c554-45b2-94e2-b981cc11a7a5o%40googlegroups.com.

Faraz Khan

unread,
Jul 30, 2020, 10:44:24 PM7/30/20
to Flutter Development (flutter-dev)
Thanks for answering @Suzuki, I read the documentation: https://api.flutter.dev/flutter/material/PopupMenuButton-class.html

My code is similar to what they have in sample code there. I think this function creates the 3 vertical dots button and it may not be suitable for onLongPress.. What should we use for onLongPress if this is not suitable?

To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.

Suzuki Tomohiro

unread,
Jul 30, 2020, 11:13:40 PM7/30/20
to Faraz Khan, Flutter Development (flutter-dev)

To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/723b9a32-2b27-4399-8ee6-9d428ca2dc80o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages