Reputation: 11
I want to close the menu after opening it with a click :
So I want to use the state of the PopupMenuButton to close it.
I tried :
_popUpKey.currentState?.dispose();
final _popUpKey = GlobalKey();
PopupMenuButton<int>(
key: _popUpKey,
onSelected: (value) {
// Handle the selected value
},
itemBuilder: (context) => [
PopupMenuItem(
value: 1,
child: Text('Option 1'),
),
PopupMenuItem(
value: 2,
child: Text('Option 2'),
),
],
Upvotes: 0
Views: 17
Reputation: 371
If you use SetState inside the onSelected help you?
onSelected: (SampleItem item) {
setState(() {
selectedItem = item;
});
},
Need to be StateFull.
More here: https://api.flutter.dev/flutter/material/PopupMenuButton-class.html
Upvotes: 0