HarrisonQi / flame-tutorial-langaw

Langaw - A tutorial project for Flutter with Flame.
28 stars 5 forks source link

Concurrent modification during iteration: Instance(length:3) of '_GrowableList'. #3

Open criusKer opened 3 years ago

criusKer commented 3 years ago

根据 “Flutter 游戏开发(flame) 01 开发2D休闲游戏:消灭小飞蝇(1/5)“ 这篇写完后,点击“小飞蝇”会报Concurrent modification during iteration: Instance(length:3) of '_GrowableList'.

HarrisonQi commented 3 years ago

仔细核对下代码, 是否有出入. 或直接clone首篇文章的仓库.

criusKer commented 3 years ago

clone试了下也是一样的

HarrisonQi commented 3 years ago

终端中输入

flutter doctor

粘贴下信息.

还有你的flame版本

criusKer commented 3 years ago
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Version 10.0.18363.1440], locale zh-CN)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
[!] Android Studio (version 4.1.0)
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Ultimate Edition (version 2018.2)
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
[√] Connected device (1 available)

! Doctor found issues in 2 categories.

flame: ^0.29.0

ShanRaw commented 3 years ago

可以尝试修改 langaw-game.dart onTapDown 方法里面forEach 改为for 并且在响应事件后 break 退出循环 flies.forEach((Fly fly) { if (fly.flyRect.contains(d.globalPosition)) { fly.onTapDown(); isHandled = true; didHitAFly = true; } }); 改为 for (int i = 0; i < files.length; i++) { if (files[i].flyRect.contains(details.globalPosition)) { files[i].onTapDown(); isHandled = true; didHitAFly = true; break; } }