idraw
idraw copied to clipboard
代码勘误
p20中的s01中的clock_manage.dart中有以下代码:
void collectDigit({int target = 0, double offsetRate = 0}) {
if (target > 10 && count > numParticles) {
return;
}
double space = _radius * 2;
double offSetX = (digits[target][0].length * 2 * (_radius + 1) + space) *
offsetRate;
for (int i = 0; i < digits[target].length; i++) {
for (int j = 0; j < digits[target][j].length; j++) {
if (digits[target][i][j] == 1) {
double rX = j * 2 * (_radius + 1) + (_radius + 1); //第(i,j)个点圆心横坐标
double rY = i * 2 * (_radius + 1) + (_radius + 1); //第(i,j)个点圆心纵坐标
particles[count] = Particle(x: rX + offSetX, //**这里第一次会发生越界,因为particles数组长度为0,从而导致程序发生异常**
y: rY, size: _radius, color: Colors.blue,
active: true);
count++;
}
}
}
}
可以修改如下
if(particles.length <= count){
//没有则增加
particles.add(Particle(x: rX + offSetX,
y: rY, size: _radius, color: Colors.blue,
active: true));
}else{
particles[count] = Particle(x: rX + offSetX,
y: rY, size: _radius, color: Colors.blue,
active: true);
}