Friday, June 11, 2021

Flutter Filter Array

List<String> SearchResult = CitiesService.getSuggestions(SearchText);

......

class CitiesService {
static final List<String> cities = [
'Beirut',
'Damascus',
'San Fransisco',
];

static List<String> getSuggestions(String query) {
List<String> matches = <String>[];
matches.addAll(cities);

matches.retainWhere((s) => s.toLowerCase().contains(query.toLowerCase()));
return matches;
}
}

No comments: