我正在尝试使用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);
},
),
),我怎么才能让它工作呢?
发布于 2021-01-22 18:39:31
List<Function> _aa = [
() {
print('hello1!');
},
() {
print('hello2!');
},
() {
print('hello!3');
},
];您忘记添加.call(),如下所示:
onSelectedItemChanged: (i) {
print(i);
_aa[i].call();
},https://stackoverflow.com/questions/65843177
复制相似问题