【发布时间】:2020-12-04 14:18:17
【问题描述】:
我想知道是否可以为我的存储库创建一个函数,我可以使用它来更改基于数据类的变量中的任何值。这可能吗,怎么做?
List<Task> tasks;
Future<void> changeTaskValue(int taskId, String variable, dynamic newValue) {
task[taskId].<magic to get a reference to the variable> = newValue;
}
class Task {
Task({this.taskId, this.taskName, this.status, });
final int taskId;
final String taskName;
final String status;
}
...
void function abc() {
changeTaskValue(taskId: 1, variable: 'taskName', newValue: 'test')
}
【问题讨论】:
-
这能回答你的问题吗? Dynamically setting variable name in Dart
-
不是真的,另一个问题是关于动态创建变量,我的关于修改
标签: flutter variables repository