[英]Flutter list values not updating
I am having troubles with my list not updating in flutter,i have a for loop to fill the code of the machines and in my list _machines that receives the data from the webservice it has a code in it but when i try to assign that code to my other list machineDetails it doesnt pass a value,我的列表没有在颤振中更新时遇到问题,我有一个 for 循环来填充机器的代码,在我的列表_machines 中,它从网络服务接收数据,其中有一个代码,但是当我尝试分配该代码时到我的另一个列表machineDetails它不传递值,
Here is the code:这是代码:
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;
});
}
Here is the output:这是输出:
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
But my list machineDetails list does get updated with the lenght of _machines list:但是我的列表machineDetails列表确实随着_machines列表的长度而更新:
I/flutter (14487): MachineDetails Lenght RegisterTime: 6
Thank you for your time and attention感谢您的时间和关注
machineDetails[i].code = _machines[i].vCodigo;
If there are no errors, I think the problem is with using machineDetails[i]?.code
so check the following updated code, it might help.如果没有错误,我认为问题在于使用
machineDetails[i]?.code
所以检查以下更新的代码,它可能会有所帮助。
......
for (int i = 0; i < _machines.length; i++) {
print('Machines $i code: ${_machines[i].vCodigo}');
machineDetails[i]=MachineDetails(); //line added
machineDetails[i].code = _machines[i].vCodigo; //line updated
print('MachineDetails $i code: ${machineDetails[i]?.code}');
......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.