flutter - 每次我打电话给我的 listView 内容都是重复的
问题描述
我有一个视图,我在其中显示列表中的所有项目。当我再次进入该视图时,所有内容都是重复的。这是我的中间件的源代码,如果我从数据库中获取内容:
if (action is GetPersonalExpAction) {
dataService.getEntity("experience/list").then((reponse) => decodeBody(reponse)).then((result) {
List<ItemExperience> experience = [];
for (var element in result) {
experience.add(ItemExperience(
id: element['id'],
job: element['job'],
company: element['company'],
date_from: element['date_from'],
date_to: element['date_to'],
description: element['description'],
));
}
store.state.personalAreaState.experience!.addAll(experience);
next(action);
});
}
我想知道我怎样才能让它停止。
解决方案
如果您需要多次调用该方法,则必须store.state.personalAreaState.experience
在添加数据库数据之前清除。像那样:
if (action is GetPersonalExpAction) {
dataService.getEntity("experience/list").then((reponse) => decodeBody(reponse)).then((result) {
List<ItemExperience> experience = [];
for (var element in result) {
experience.add(ItemExperience(
id: element['id'],
job: element['job'],
company: element['company'],
date_from: element['date_from'],
date_to: element['date_to'],
description: element['description'],
));
}
store.state.personalAreaState.experience!.clear(); //<-- clear list before add data
store.state.personalAreaState.experience!.addAll(experience);
next(action);
});
}
推荐阅读
- excel - Excel 动态表与另一个工作表中的数据
- mysql - ER_PARSE_ERROR:您的 SQL 语法有错误 - Node JS
- security - 使用 AspNetUserTokens 表在 ASP.NET Core Web Api 中存储刷新令牌
- python - 如何从列表中删除所有符合特定格式的字符串?
- web-config -
不工作? - linq - LINQ 使用多对多关系聚合结果
- google-chrome - 在扩展加载而不是页面加载时运行 contentscript
- ruby-on-rails - 子对象无法在 before_destroy 回调中删除父对象
- ios - Xcode 10.1 无法找到或创建 iOS 模拟器
- c# - NU1107 在单元测试项目中检测到版本冲突