如何将数据传递给 PopupMenuButton 小部件的 onSelected 方法?

mir*_*cal 0 flutter

我正在尝试通过 PopupMenuButton 删除我的卡片。

日卡

但是我无法将有关当前卡的任何信息传递给它的onSelected方法,它需要String并返回void.

onSelected: (String value) { print('Selected: $value'); },
Run Code Online (Sandbox Code Playgroud)

Kee*_*ani 5

只需从那里调用另一个函数并传递您的值 -

onSelected: (Choice choice) {
          callMethod('some data I am passing');
        },
Run Code Online (Sandbox Code Playgroud)

然后像这样调用你的方法 -

callMethod(String data) {
print(data);}
Run Code Online (Sandbox Code Playgroud)