Add onlyCountries property

- to define a list with specific country codes to show only such countries
This commit is contained in:
Yoan Carlos Machado Espinosa
2019-08-22 08:45:52 -04:00
parent ce9d724747
commit a576443eda

View File

@@ -31,10 +31,14 @@ class CountryCodePicker extends StatefulWidget {
/// shows the flag /// shows the flag
final bool showFlag; final bool showFlag;
/// contains the country codes to load only the specified countries.
final List<String> onlyCountries;
CountryCodePicker({ CountryCodePicker({
this.onChanged, this.onChanged,
this.initialSelection, this.initialSelection,
this.favorite = const [], this.favorite = const [],
this.onlyCountries = const [],
this.textStyle, this.textStyle,
this.padding = const EdgeInsets.all(0.0), this.padding = const EdgeInsets.all(0.0),
this.showCountryOnly = false, this.showCountryOnly = false,
@@ -59,6 +63,12 @@ class CountryCodePicker extends StatefulWidget {
)) ))
.toList(); .toList();
if(onlyCountries.length > 0) {
elements = elements
.where((c) => onlyCountries.contains(c.code))
.toList();
}
return new _CountryCodePickerState(elements); return new _CountryCodePickerState(elements);
} }
} }