Created
September 22, 2022 09:07
-
-
Save harsh1772/2d4485d5ac4a57db3f8cd4c899635f7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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