Merge pull request #70 from imtoori/hotfix/search-localizations
Hotfix/search localizations
This commit is contained in:
@@ -17,7 +17,7 @@ class _MyAppState extends State<MyApp> {
|
||||
supportedLocales: [
|
||||
Locale('en'),
|
||||
Locale('it'),
|
||||
Locale('en'),
|
||||
Locale('fr'),
|
||||
],
|
||||
localizationsDelegates: [
|
||||
CountryLocalizations.delegate,
|
||||
@@ -67,7 +67,7 @@ class _MyAppState extends State<MyApp> {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: CountryCodePicker(
|
||||
onChanged: print,
|
||||
onChanged: (e) => print(e.toLongString()),
|
||||
initialSelection: 'TF',
|
||||
showCountryOnly: true,
|
||||
showOnlyCountryWhenClosed: true,
|
||||
|
||||
@@ -59,13 +59,9 @@ class CountryCode {
|
||||
@override
|
||||
String toString() => "$dialCode";
|
||||
|
||||
String toLongString([BuildContext context]) =>
|
||||
"$dialCode ${toCountryStringOnly(context)}";
|
||||
String toLongString() => "$dialCode ${toCountryStringOnly()}";
|
||||
|
||||
String toCountryStringOnly([BuildContext context]) {
|
||||
if (context != null) {
|
||||
return CountryLocalizations.of(context)?.translate(code) ?? name;
|
||||
}
|
||||
String toCountryStringOnly() {
|
||||
return '$name';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
|
||||
child: Text(
|
||||
widget.showOnlyCountryWhenClosed
|
||||
? selectedItem.toCountryStringOnly(context)
|
||||
? selectedItem.toCountryStringOnly()
|
||||
: selectedItem.toString(),
|
||||
style: widget.textStyle ?? Theme.of(context).textTheme.button,
|
||||
overflow: widget.textOverflow,
|
||||
@@ -168,6 +168,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
void didUpdateWidget(CountryCodePicker oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
|
||||
this.elements = elements.map((e) => e.localize(context)).toList();
|
||||
_onInit(selectedItem);
|
||||
|
||||
if (oldWidget.initialSelection != widget.initialSelection) {
|
||||
@@ -233,13 +234,13 @@ class CountryCodePickerState extends State<CountryCodePicker> {
|
||||
|
||||
void _publishSelection(CountryCode e) {
|
||||
if (widget.onChanged != null) {
|
||||
widget.onChanged(e.localize(context));
|
||||
widget.onChanged(e);
|
||||
}
|
||||
}
|
||||
|
||||
void _onInit(CountryCode e) {
|
||||
if (widget.onInit != null) {
|
||||
widget.onInit(e.localize(context));
|
||||
widget.onInit(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,8 +126,8 @@ class _SelectionDialogState extends State<SelectionDialog> {
|
||||
flex: 4,
|
||||
child: Text(
|
||||
widget.showCountryOnly
|
||||
? e.toCountryStringOnly(context)
|
||||
: e.toLongString(context),
|
||||
? e.toCountryStringOnly()
|
||||
: e.toLongString(),
|
||||
overflow: TextOverflow.fade,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user