[英]I want to create multiple filter list with dropdown in flutter/dart
I'm a new flutter developer.我是新的 flutter 开发人员。
So I want to create multiple filter lists with dropdowns...所以我想用下拉菜单创建多个过滤器列表......
This filter has 3 dropdown widgets, the expected result of this is that the search results can be combined with each other.这个过滤器有 3 个下拉小部件,这样做的预期结果是搜索结果可以相互组合。
I'm kinda confused about how to start doing it, can you give me advice/reference/link related to this issue.我对如何开始做有点困惑,你能给我与这个问题相关的建议/参考/链接吗?
So far I just can do a single search (i got it from the search delegate)到目前为止,我只能进行一次搜索(我是从搜索代表那里得到的)
Future<List<ModelKost>> getFilter({String? query}) async {
final prefs = await SharedPreferences.getInstance();
const key = 'token';
final value = prefs.get(key) ?? 0;
try {
var response = await http.get(Uri.parse('$serverUrl/home'), headers: {
'Accept': 'application/json',
'Authorization': 'Bearer $value'
});
if (response.statusCode == 200) {
data = json.decode(response.body)['data'];
results = data.map((e) => ModelKost.fromJson(e)).toList();
if (query != null) {
results = results
.where((e) =>
e.kabkot.toLowerCase().contains((query.toLowerCase())))
.toList();
}
} else {
debugPrint('fetch data error');
}
} on Exception catch (e) {
debugPrint('error: $e');
}
sortHarga = results;
return results;
}
How to implement it with multiple filters and with dropdown?如何使用多个过滤器和下拉菜单来实现它? thank you!谢谢你!
What you want to do is after the api call, store the result inside a list (for example allKosts).您要做的是在 api 调用之后,将结果存储在列表中(例如 allKosts)。 Then provide a getter to get the list, with the filter.然后提供一个 getter 来获取列表,带有过滤器。 Whenever you change a filter, you want to call setState and the getter's value will be updated automatically.每当您更改过滤器时,您都希望调用 setState 并且 getter 的值将自动更新。
List<ModelKost> allKosts = [];
String kabkotFilter = '';
String tipeKotFilter = '';
List<ModelKost> get filteredKosts =>
results.where((e) => e.kabkot.toLowerCase().contains((kabkotFilter.toLowerCase())) && e.tipeKot.toLowerCase() == tipeKotFilter.toLowerCase())).toList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.