Reputation: 33
I am pretty new to flutter and I found the code for my PopupMenuButton online and modified it slightly. I want the logout option to run Navigator.pop(context), but I don't understand how to get it get it there. Code:
PopupMenuButton<String>(
onSelected: handleClick,
itemBuilder: (context) {
return {'Logout', 'Settings'}.map((String choice) {
return PopupMenuItem<String>(
value: choice,
child: Text(choice)
);
}).toList();
}
),
And I want to send it in here:
void handleClick(String value, BuildContext context) {
switch (value) {
case 'Logout':
storage.deleteAll();
//Navigator.pop();
break;
case 'Settings':
break;
}
}
I also tried making Buildcontext a global final late variable, but it seemed to cause a lot of problems. To be honest, I don't understand how the PopupMenuButton works in regards to calling the funtion, thus me not knowing how to pass another argument Thanks for the help
Upvotes: 0
Views: 155
Reputation: 5746
Write onSelected
like this instead:
onSelected: (value) {
handleClick(value, context);
},
Upvotes: 1