对于循环计算,在几个循环后给出 null



我想从用户输入中制作一个图形,当用户输入数字并按下按钮时,onpress函数进入for循环以计算所有图形点。 但是现在 for 循环给出了错误的值,经过一定数量的循环后,它开始在这里和那里给出 null 值, 不知道是什么原因造成的。

这是我的 onPressed 函数:

onPressed: () {
setState(() {
for (int i = 1; i <= 20; i++) {
for (int j = 0; j < 6; j++) {
value1 = 0.0;
print(i.toString() + ' , ' + j.toString());
if (j == 0) {
value1 = (_finalDrive *
(i * 10 * mphtokmph) *
_gear1 *
_coefficient) /
_tireDiameter;
} else if (j == 1) {
value1 = (_finalDrive *
(i * 10 * mphtokmph) *
_gear2 *
_coefficient) /
_tireDiameter;
} else if (j == 2) {
value1 = (_finalDrive *
(i * 10 * mphtokmph) *
_gear3 *
_coefficient) /
_tireDiameter;
} else if (j == 3) {
value1 = (_finalDrive *
(i * 10 * mphtokmph) *
_gear4 *
_coefficient) /
_tireDiameter;
} else if (j == 4) {
value1 = (_finalDrive *
(i * 10 * mphtokmph) *
_gear5 *
_coefficient) /
_tireDiameter;
} else if (j == 5) {
value1 = (_finalDrive *
(i * 10 * mphtokmph) *
_gear6 *
_coefficient) /
_tireDiameter;
}
values[int.parse(((j) * (i)).toStringAsFixed(0))] =
value1;
}
}
});
},

输出是这样的:I/flutter (21824): [47049.25, 1383.39, 2766.77, 4150.16, 5533.55, 6916.93, 8300.32, 9683.7, 11067.09, 12450.48, 13833.86, 15217.25, 16600.64, 17984.02, 19367.41, 20750.8, 22134.18, 23517.57, 24900.96, 26284.34, 27667.73, 4940.67, 10504.56, null, 11459.52, 2075.08, 12414.48, 6352.28, 13369.44, null, 14324.4, null, 15279.36, 7763.9, 16234.32, 2905.11, 17189.28, null, 18144.24, 9175.52, 19099.2, null, 9881.33, null, 5652.12, 10587.14, null, null, 11292.95, null, 4150.16, 11998.76, 6679.78, null, 12704.57, 4565.18, 7193.61, 13410.38, null, null, 14116.19, null, null, null, 8221.27, 5395.21, 4565.18, null, 8735.1, null, 5810.22, null, 9248.93, null, null, 6225.24, 9762.76, null, 5395.21, null, 10276.58, null, null, null, 5810.22, 7055.27, null, null, null, null, 7470.29, null, null, null, null, 7885.3, 6640.25, null, null, null, 8300.32, null, 7055.27, null, null, null, null, null, 7470.29, null, null, null, null, null, 7885.3, null, null, null, null, null]

数组索引的问题 代码

indice = -1 
For loop1...
For loop2...
indice = indice +1 
:
:
value[indice] = value1

相关内容

  • 没有找到相关文章

最新更新