【发布时间】:2020-04-19 02:53:01
【问题描述】:
我的列表无法在颤动中更新时遇到问题,我有一个 for 循环来填充机器的代码,并且在我的列表 _machines 中接收来自网络服务的数据,它有一个代码在其中,但是当我尝试将该代码分配给我的其他列表时 machineDetails 它没有传递值,
代码如下:
Future<void> _registerTime(int index) async {
try {
setState(() {
_loading = true;
});
String res = await gruposRepo.timeRegisterWorks(widget.worker.toString(),
widget.work, widget.product, widget.task, _machines[index].vCodigo);
print(res);
print("MachineDetails Lenght RegisterTime: ${machineDetails.length}");
for (int i = 0; i < _machines.length; i++) {
print('Machines $i code: ${_machines[i].vCodigo}');
machineDetails[i]?.code = _machines[i].vCodigo;
print('MachineDetails $i code: ${machineDetails[i]?.code}');
if (res == '1') {
machineDetails[i]?.working = true;
} else if (res == '2') {
machineDetails[i]?.working = false;
}
}
print(machineDetails[index]?.working);
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(Translations.of(context).trans('saved')),
actions: <Widget>[
FlatButton(
child: Text('OK'),
onPressed: () => Navigator.of(context).pop(),
)
],
);
});
} catch (e) {
this._errorMsg = e.toString();
}
setState(() {
_loading = false;
});
}
这是输出:
I/flutter (14487): Machines 0 code: 4
I/flutter (14487): MachineDetails 0 code: null
I/flutter (14487): Machines 1 code: 3
I/flutter (14487): MachineDetails 1 code: null
I/flutter (14487): Machines 2 code: 22
I/flutter (14487): MachineDetails 2 code: null
I/flutter (14487): Machines 3 code: 9
I/flutter (14487): MachineDetails 3 code: null
I/flutter (14487): Machines 4 code: 25
I/flutter (14487): MachineDetails 4 code: null
I/flutter (14487): Machines 5 code: 26
I/flutter (14487): MachineDetails 5 code: null
但我的列表 machineDetails 列表确实会更新为 _machines 列表的长度:
I/flutter (14487): MachineDetails Lenght RegisterTime: 6
感谢您的时间和关注
【问题讨论】:
-
控制台可能有一些错误?否则显示 MachineDetails 类会有所帮助..
-
控制台没有任何错误,我的 MachineDetails 类如下: class MachineDetails { String code;布尔工作; }