When I add some elements in HashMap in flutter like this:
void loadingMoreChannel(RefreshController _refreshController) async {
articleRequest.pageNum = articleRequest.pageNum 1;
List<Channel> channels = await Repo.getChannels(articleRequest);
channels.addAll(channels);
_refreshController.loadComplete();
}
first step fetched some channel information from the server side, then add the channel info into List, shows error:
Concurrent modification during iteration: Instance(length:15) of '_GrowableList'.<…>
what should I do to add the channel elements into list concurrent?
CodePudding user response:
Seems you need to rename the variable. You can just do
void loadingMoreChannel(RefreshController _refreshController) async {
articleRequest.pageNum = articleRequest.pageNum 1;
List<Channel> result = await Repo.getChannels(articleRequest);
channels.addAll(result); //it was having same name
_refreshController.loadComplete();
}