Skip to content

Instantly share code, notes, and snippets.

@harsh1772
Created September 22, 2022 09:07
Show Gist options
  • Save harsh1772/2d4485d5ac4a57db3f8cd4c899635f7d to your computer and use it in GitHub Desktop.
Save harsh1772/2d4485d5ac4a57db3f8cd4c899635f7d to your computer and use it in GitHub Desktop.
TextEditingController searchCountry = TextEditingController();
List<Map<String, dynamic>> allCountry = [];
@override
void initState() {
super.initState();
allCountry = CountryPick().countries;
}
void searchCountryName(String enteredKeyword) {
List<Map<String, dynamic>> results = [];
if (enteredKeyword.isEmpty) {
// if the search field is empty or only contains white-space, we'll display all users
results = CountryPick().countries;
} else {
results = CountryPick()
.countries
.where((country) => country["english_name"]
.toLowerCase()
.contains(enteredKeyword.toLowerCase()))
.toList();
// we use the toLowerCase() method to make it case-insensitive
}
// Refresh the UI
setState(() {
allCountry = results;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment