gpt4 book ai didi

dart - 使用列表访问 dart flutter 中的函数

转载 作者:IT王子 更新时间:2023-10-29 07:23:16 26 4
gpt4 key购买 nike

如何通过列表访问函数?

我有这样的东西:

  List processList = [
[001, 'Volume', 0.8,0,0],
[002, 'Complexity', 0.5,0,0],
[003, 'Silence', 0.3,0,0],
[004, 'Notice', 0.3,0,0],
....];

我希望 001、002 等成为我可以调用的函数

processList[i][0] ();

就像一个函数列表...

我无法以某种方式弄清楚它的语法,我唯一能做的就是用函数的结果填充列表,但这不是我需要的。

最佳答案

尝试

void main() {
List processList = [
[(){print('London');}, 'Volume', 0.8, 0, 0],
[(){print('Aarhus');}, 'Complexity', 0.5, 0, 0],
[(){print('Munich');}, 'Silence', 0.3, 0, 0],
[(){print('LA');}, 'Notice', 0.3, 0, 0],
];
int i = 3;
processList[i][0]();
}

打印 LA。看typedefs声明函数签名的方法。

关于dart - 使用列表访问 dart flutter 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54452540/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com