To use the Country Picker look at the example below :
Example Usage:
class_MyHomePageStateextendsState<MyHomePage> {
CountryPicker countryPicker;
Country country = Country.fromJson(countryCodes[0]); // select initial country @overridevoidinitState() {
super.initState();
countryPicker = CountryPicker(onCountrySelected: (Country country) {
print(country);
setState(() {
this.country = country;
});
});
}
@overrideWidgetbuild(BuildContext context) {
// To simply launch the country picker// use countryPicker.launch(context)// to forcefully dismiss use countryPicker.dismiss()// simple example could bereturnGestureDetector(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image:
AssetImage(country.flagUri, package: 'ola_like_country_picker'),
),
),
),
onTap: () {
countryPicker.launch(context);
},
);
}
}
Output
Parameters
parameter
default
required
type
remark
onCountrySelected
null
yes
OnCountrySelectedCallback
called when country is selected.
showTitle
true
no
bool
whether to show title or not.
titleText
"Select your country"
no
String
text for title.
To simply use country list view any where use CountryListView() and to modify attributes like flagWidth, flagHeight, countryTitle style etc use below arguments like