I create a function showPopupMenu because I need this multiple times in this project. When I will click an item on showPopupMenu that time I need the clicked position on the main page. How can I do this?
Here is my main page code:
return MaterialApp(
home: Scaffold(
appBar: const CustomToolbar(title: 'Test Screen'),
body: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Padding(
padding: EdgeInsets.only(left: 10),
child: Text('Notice Board',
style: TextStyle(
fontFamily: 'Montserrat Bold',
color: Colors.black)),
),
InkWell(
onTapDown: (TapDownDetails tap) {
var menus = <String>['Edit', 'Delete'];
showPopupMenu(context, tap, menus);
//I want to clicked position here
},
child: const Icon(Icons.more_vert, color: Colors.grey))
],
)
],
)),
);
And here is my showPopupMenu method code:
void showPopupMenu(
BuildContext context, TapDownDetails tap, List<String> menus) async { await showMenu(
context: context,
position: RelativeRect.fromLTRB(
tap.globalPosition.dx, tap.globalPosition.dy, 0, 0),
items: [
if (menus.isNotEmpty)
PopupMenuItem<String>(
value: menus[0], onTap: () {}, child: Text(menus[0])),
if (menus.length > 1)
PopupMenuItem<String>(value: menus[1], child: Text(menus[1])),
if (menus.length > 2)
PopupMenuItem<String>(value: menus[2], child: Text(menus[2])),
if (menus.length > 3)
PopupMenuItem<String>(value: menus[3], child: Text(menus[3]))
],
elevation: 8.0);}