diff --git a/example/lib/main.dart b/example/lib/main.dart index cdebcaf..ad5a759 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -17,7 +17,7 @@ class _MyAppState extends State { supportedLocales: [ Locale('en'), Locale('it'), - Locale('en'), + Locale('fr'), ], localizationsDelegates: [ CountryLocalizations.delegate, @@ -67,7 +67,7 @@ class _MyAppState extends State { child: Padding( padding: const EdgeInsets.all(8.0), child: CountryCodePicker( - onChanged: print, + onChanged: (e) => print(e.toLongString()), initialSelection: 'TF', showCountryOnly: true, showOnlyCountryWhenClosed: true, diff --git a/lib/country_code.dart b/lib/country_code.dart index 13c1381..627b0c6 100644 --- a/lib/country_code.dart +++ b/lib/country_code.dart @@ -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'; } } diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 7dbaac5..e522a69 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -151,7 +151,7 @@ class CountryCodePickerState extends State { 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 { 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 { 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); } } } diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index ae6beb2..15d0a65 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -126,8 +126,8 @@ class _SelectionDialogState extends State { flex: 4, child: Text( widget.showCountryOnly - ? e.toCountryStringOnly(context) - : e.toLongString(context), + ? e.toCountryStringOnly() + : e.toLongString(), overflow: TextOverflow.fade, ), ),