【发布时间】:2021-06-13 06:25:56
【问题描述】:
我在过滤列表方面需要帮助。
我在 initState 中填充列表:
Future _organisations;
Future<void> readJson() async {
final String response =
await rootBundle.loadString('assets/organisations.json');
final data = await json.decode(response);
List<Organization> temp = [];
for (var item in data) {
Organization place = Organization(
address: item['Address'],
contactInfo: item['Contact info'],
organization: item['Organization'],
phoneNumber: item['Phone number'],
shortDescription: item['Short description'],
subject: item['Subject'],
tags: item['Tags'],
);
temp.add(place);
}
temp.sort((a, b) => a.organization.compareTo(b.organization));
return temp;
}
@override
void initState() {
super.initState();
_organisations = readJson();
}
然后我在列表上方有一个按钮,我想用它来使用 setState 过滤列表,但是它不起作用。如何过滤 Future 类型的列表?
【问题讨论】:
标签: list flutter dart filter future