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