Skip to content

Commit

Permalink
9.2.2 language (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedvdb committed Mar 27, 2024
1 parent a1e06e0 commit b7a6f38
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 153 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [9.2.2]
- added language selection to demo
- fixed a bug where country selection language

## [9.2.1]
- fix readme

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ This package uses the `flutter_country_selector` package under the hood, which e
- hi
- hu
- it
- ku
- nb
- nl
- pt
Expand Down
Binary file modified demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
145 changes: 92 additions & 53 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,40 @@ void main() {
// For a simpler example see the README

class PhoneFieldView extends StatelessWidget {
static const supportedLocales = [
Locale('ar'),
// not supported by material yet
// Locale('ckb'),
Locale('de'),
Locale('el'),
Locale('en'),
Locale('es'),
Locale('fa'),
Locale('fr'),
Locale('hi'),
Locale('hu'),
Locale('it'),
// not supported by material yet
// Locale('ku'),
Locale('nb'),
Locale('nl'),
Locale('pt'),
Locale('ru'),
Locale('sv'),
Locale('tr'),
Locale('uz'),
Locale('zh'),
// ...
];

final PhoneController controller;
final FocusNode focusNode;
final CountrySelectorNavigator selectorNavigator;
final bool withLabel;
final bool outlineBorder;
final bool isCountryButtonPersistant;
final bool mobileOnly;
final bool useRtl;
final Locale locale;

const PhoneFieldView({
Key? key,
Expand All @@ -28,7 +54,7 @@ class PhoneFieldView extends StatelessWidget {
required this.outlineBorder,
required this.isCountryButtonPersistant,
required this.mobileOnly,
required this.useRtl,
required this.locale,
}) : super(key: key);

PhoneNumberInputValidator? _getValidator(BuildContext context) {
Expand All @@ -44,36 +70,42 @@ class PhoneFieldView extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AutofillGroup(
child: Directionality(
textDirection: useRtl ? TextDirection.rtl : TextDirection.ltr,
child: PhoneFormField(
focusNode: focusNode,
controller: controller,
isCountryButtonPersistent: isCountryButtonPersistant,
autofocus: false,
autofillHints: const [AutofillHints.telephoneNumber],
countrySelectorNavigator: selectorNavigator,
decoration: InputDecoration(
label: withLabel ? const Text('Phone') : null,
border: outlineBorder
? const OutlineInputBorder()
: const UnderlineInputBorder(),
hintText: withLabel ? '' : 'Phone',
),
enabled: true,
countryButtonStyle: const CountryButtonStyle(
showFlag: true,
showIsoCode: false,
showDialCode: true,
showDropdownIcon: true,
),
validator: _getValidator(context),
autovalidateMode: AutovalidateMode.onUserInteraction,
cursorColor: Theme.of(context).colorScheme.primary,
// ignore: avoid_print
onSaved: (p) => print('saved $p'),
// ignore: avoid_print
onChanged: (p) => print('changed $p'),
child: Localizations.override(
context: context,
locale: locale,
child: Builder(
builder: (context) {
final label = PhoneFieldLocalization.of(context).phoneNumber;
return PhoneFormField(
focusNode: focusNode,
controller: controller,
isCountryButtonPersistent: isCountryButtonPersistant,
autofocus: false,
autofillHints: const [AutofillHints.telephoneNumber],
countrySelectorNavigator: selectorNavigator,
decoration: InputDecoration(
label: withLabel ? Text(label) : null,
border: outlineBorder
? const OutlineInputBorder()
: const UnderlineInputBorder(),
hintText: withLabel ? '' : label,
),
enabled: true,
countryButtonStyle: const CountryButtonStyle(
showFlag: true,
showIsoCode: false,
showDialCode: true,
showDropdownIcon: true,
),
validator: _getValidator(context),
autovalidateMode: AutovalidateMode.onUserInteraction,
cursorColor: Theme.of(context).colorScheme.primary,
// ignore: avoid_print
onSaved: (p) => print('saved $p'),
// ignore: avoid_print
onChanged: (p) => print('changed $p'),
);
},
),
),
);
Expand All @@ -87,19 +119,8 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
localizationsDelegates: PhoneFieldLocalization.delegates,
supportedLocales: const [
Locale('en', ''),
Locale('fr', ''),
Locale('es', ''),
Locale('el', ''),
Locale('de', ''),
Locale('it', ''),
Locale('ru', ''),
Locale('sv', ''),
Locale('tr', ''),
Locale('zh', ''),
// ...
],
supportedLocales: PhoneFieldView.supportedLocales,
locale: const Locale('en'),
title: 'Phone field demo',
theme: ThemeData(
brightness: Brightness.dark,
Expand All @@ -125,9 +146,9 @@ class PhoneFormFieldScreenState extends State<PhoneFormFieldScreen> {
bool mobileOnly = true;
bool isCountryButtonPersistent = true;
bool withLabel = true;
bool useRtl = false;
CountrySelectorNavigator selectorNavigator =
const CountrySelectorNavigator.page();
Locale locale = const Locale('en');
final formKey = GlobalKey<FormState>();

@override
Expand Down Expand Up @@ -179,12 +200,30 @@ class PhoneFormFieldScreenState extends State<PhoneFormFieldScreen> {
onChanged: (v) => setState(() => mobileOnly = v),
title: const Text('Mobile phone number only'),
),
SwitchListTile(
value: useRtl,
onChanged: (v) {
setState(() => useRtl = v);
},
title: const Text('RTL'),
ListTile(
title: Wrap(
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
const Text('Language: '),
DropdownButton<Locale>(
value: locale,
onChanged: (Locale? value) {
if (value != null) {
setState(() => locale = value);
}
},
items: [
for (final locale
in PhoneFieldView.supportedLocales)
DropdownMenuItem(
value: locale,
child: Text(locale.toLanguageTag()),
),
],
),
],
),
),
ListTile(
title: Wrap(
Expand Down Expand Up @@ -244,7 +283,7 @@ class PhoneFormFieldScreenState extends State<PhoneFormFieldScreen> {
isCountryButtonPersistant:
isCountryButtonPersistent,
mobileOnly: mobileOnly,
useRtl: useRtl,
locale: locale,
),
],
),
Expand Down
10 changes: 5 additions & 5 deletions l10n/ku.arb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"@@locale": "ku",
"invalidPhoneNumber": "ژمارەی تەلەفۆنی نادروست",
"invalidCountry": "وڵاتێکی نادروست",
"invalidMobilePhoneNumber": "ژمارەی مۆبایل نادروستە",
"invalidFixedLinePhoneNumber": "ژمارەی تەلەفۆنی هێڵی جێگیر نادروستە",
"requiredPhoneNumber": "ژمارەی تەلەفۆنی پێویست",
"invalidPhoneNumber": "Hejmara têlefonê nederbasdar e",
"invalidCountry": "Welatê nederbasdar",
"invalidMobilePhoneNumber": "Hejmara têlefona desta nederbasdar e",
"invalidFixedLinePhoneNumber": "Hejmara têlefonê ya xeta sabît nederbasdar e",
"requiredPhoneNumber": "Hejmara têlefonê ya pêwîst",
"selectACountrySemanticLabel": "Welatek hilbijêre, bijartina niha: {countryName} {dialCode}",
"@selectACountrySemanticLabel": {
"description": "semantic description of the country button",
Expand Down
Loading

0 comments on commit b7a6f38

Please sign in to comment.