Flutter: CupertinoPicker触发列表内的函数



我正在尝试用CupertinoPicker触发列表内的函数。

var _aa = [
() {
print('hello1!');
},
() {
print('hello2!');
},
() {
print('hello!3');
},
];

尝试执行_aa的功能。然而,当我试图在CupertinoPicker中使用它时,我得到Avoid using unnecessary statements.语句。

CupertinoPicker(
backgroundColor: Colors.white,
onSelectedItemChanged: (i) {
print(i);
_aa[i]; <--- error statement
},
itemExtent: 32.0,
children: List.generate(
_aa.length,
(i) {
print(i);
},
),
),

我怎样才能使它工作?

List<Function> _aa = [
() {
print('hello1!');
},
() {
print('hello2!');
},
() {
print('hello!3');
},
];

忘记添加.call(),如下所示:

onSelectedItemChanged: (i) {
print(i);
_aa[i].call();
},

最新更新