Reputation: 5365
I'm trying to delete my Cards via PopupMenuButton.
But I can't pass any info about current card to its onSelected
method, it takes String
and returns void
.
onSelected: (String value) { print('Selected: $value'); },
Upvotes: 0
Views: 3713
Reputation: 1472
PopupMenuButton<String>(
itemBuilder: (context) => [
PopupMenuItem(
child: Text("Edit"),
value: "edit",
),
PopupMenuItem(
child: Text("Delete"),
value: "del",
)
],
onSelected: (String val) {
print(val);
},
)
Upvotes: 0
Reputation: 21
If someone is facing the same issue still,
In PopupMenuItem you have to specify the value parameter so when a popup item
is clicked it sends the corresponding value to onSelected method
PopupMenuItem(
value: value,
child: Text(value));
}
Upvotes: 0
Reputation: 5381
Just call another function from there and pass your value -
onSelected: (Choice choice) {
callMethod('some data I am passing');
},
and then call your method like this-
callMethod(String data) {
print(data);}
Upvotes: 6