Skip to content

Commit

Permalink
Fix rtl (#230)
Browse files Browse the repository at this point in the history
* saving

* slots

* saving

* fix rtl
  • Loading branch information
cedvdb committed Mar 26, 2024
1 parent 3e584d5 commit b96ef68
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 37 deletions.
45 changes: 45 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "phone_form_field",
"request": "launch",
"type": "dart"
},
{
"name": "phone_form_field (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "phone_form_field (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "example",
"cwd": "example",
"request": "launch",
"type": "dart"
},
{
"name": "example (profile mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "example (release mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Pending

## [9.1.1]
- add Hungarian localization messages
- fix RTL

## [9.1.0]

Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C8080294A63A400263BE5 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 2 additions & 2 deletions example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This is a generated file; do not edit or check into version control.
FLUTTER_ROOT=C:\dev\flutter
FLUTTER_APPLICATION_PATH=C:\Users\cedva\Documents\Dev\countries\phone_form_field\example
FLUTTER_ROOT=/Users/cedvdb/Development/flutter
FLUTTER_APPLICATION_PATH=/Users/cedvdb/Development/libs/country/phone_form_field/example
COCOAPODS_PARALLEL_CODE_SIGN=true
FLUTTER_BUILD_DIR=build
FLUTTER_BUILD_NAME=1.0.0
Expand Down
4 changes: 2 additions & 2 deletions example/macos/Flutter/ephemeral/flutter_export_environment.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\dev\flutter"
export "FLUTTER_APPLICATION_PATH=C:\Users\cedva\Documents\Dev\countries\phone_form_field\example"
export "FLUTTER_ROOT=/Users/cedvdb/Development/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/cedvdb/Development/libs/country/phone_form_field/example"
export "COCOAPODS_PARALLEL_CODE_SIGN=true"
export "FLUTTER_BUILD_DIR=build"
export "FLUTTER_BUILD_NAME=1.0.0"
Expand Down
5 changes: 3 additions & 2 deletions lib/src/phone_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PhoneFormField extends FormField<PhoneNumber> {
final TextStyle? style;
final TextStyle? countryCodeStyle;
final StrutStyle? strutStyle;
final TextAlign textAlign;
final TextAlign? textAlign;
final TextAlignVertical? textAlignVertical;
final bool autofocus;
final String obscuringCharacter;
Expand Down Expand Up @@ -149,7 +149,8 @@ class PhoneFormField extends FormField<PhoneNumber> {
this.style,
this.countryCodeStyle,
this.strutStyle,
this.textAlign = TextAlign.start,
@Deprecated('Has no effect, Change text directionality instead')
this.textAlign,
this.textAlignVertical,
this.autofocus = false,
this.obscuringCharacter = '*',
Expand Down
90 changes: 64 additions & 26 deletions lib/src/phone_form_field_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,20 @@ class PhoneFormFieldState extends FormFieldState<PhoneNumber> {
}

Widget builder() {
final textAlignment = _computeTextAlign();
final countryButtonForEachSlot =
_buildCountryButtonForEachSlot(textAlignment);
return PhoneFieldSemantics(
hasFocus: focusNode.hasFocus,
enabled: widget.enabled,
inputDecoration: widget.decoration,
child: TextField(
decoration: widget.decoration.copyWith(
errorText: errorText,
prefixIcon: widget.isCountryButtonPersistent
? _buildCountryCodeChip(context)
: null,
prefix: widget.isCountryButtonPersistent
? null
: _buildCountryCodeChip(context),
prefix: countryButtonForEachSlot[_CountryButtonSlot.prefix],
prefixIcon: countryButtonForEachSlot[_CountryButtonSlot.prefixIcon],
suffix: countryButtonForEachSlot[_CountryButtonSlot.suffix],
suffixIcon: countryButtonForEachSlot[_CountryButtonSlot.suffixIcon],
),
controller: controller._formattedNationalNumberController,
focusNode: focusNode,
Expand All @@ -99,12 +100,12 @@ class PhoneFormFieldState extends FormFieldState<PhoneNumber> {
'[${AllowedCharacters.plus}${AllowedCharacters.digits}${AllowedCharacters.punctuation}]')),
],
onChanged: _onTextfieldChanged,
textAlign: _computeTextAlign(),
autofillHints: widget.autofillHints,
keyboardType: widget.keyboardType,
textInputAction: widget.textInputAction,
style: widget.style,
strutStyle: widget.strutStyle,
textAlign: widget.textAlign,
textAlignVertical: widget.textAlignVertical,
autofocus: widget.autofocus,
obscuringCharacter: widget.obscuringCharacter,
Expand Down Expand Up @@ -136,26 +137,56 @@ class PhoneFormFieldState extends FormFieldState<PhoneNumber> {
);
}

Widget _buildCountryCodeChip(BuildContext context) {
TextAlign _computeTextAlign() {
final directionality = Directionality.of(context);
return directionality == TextDirection.ltr
? TextAlign.start
: TextAlign.end;
}

/// returns where the country button is placed in the input
Map<_CountryButtonSlot, Widget?> _buildCountryButtonForEachSlot(
TextAlign textAlign,
) {
final countryButton = _buildCountryButton(context);
if (textAlign == TextAlign.start) {
if (widget.isCountryButtonPersistent) {
return {_CountryButtonSlot.prefixIcon: countryButton};
} else {
return {_CountryButtonSlot.prefix: countryButton};
}
} else {
if (widget.isCountryButtonPersistent) {
return {_CountryButtonSlot.suffixIcon: countryButton};
} else {
return {_CountryButtonSlot.suffix: countryButton};
}
}
}

Widget _buildCountryButton(BuildContext context) {
return ExcludeFocus(
child: AnimatedBuilder(
animation: controller,
builder: (context, _) => CountryButton(
key: const ValueKey('country-code-chip'),
isoCode: controller.value.isoCode,
onTap: widget.enabled ? _selectCountry : null,
padding: _computeCountryButtonPadding(context),
showFlag: widget.showFlagInInput,
showIsoCode: widget.showIsoCodeInInput,
showDialCode: widget.showDialCode,
textStyle: widget.countryCodeStyle ??
widget.decoration.labelStyle ??
TextStyle(
fontSize: 16,
color: Theme.of(context).textTheme.bodySmall?.color,
),
flagSize: widget.flagSize,
enabled: widget.enabled,
child: Directionality(
textDirection: TextDirection.ltr,
child: AnimatedBuilder(
animation: controller,
builder: (context, _) => CountryButton(
key: const ValueKey('country-code-chip'),
isoCode: controller.value.isoCode,
onTap: widget.enabled ? _selectCountry : null,
padding: _computeCountryButtonPadding(context),
showFlag: widget.showFlagInInput,
showIsoCode: widget.showIsoCodeInInput,
showDialCode: widget.showDialCode,
textStyle: widget.countryCodeStyle ??
widget.decoration.labelStyle ??
TextStyle(
fontSize: 16,
color: Theme.of(context).textTheme.bodySmall?.color,
),
flagSize: widget.flagSize,
enabled: widget.enabled,
),
),
),
);
Expand Down Expand Up @@ -197,3 +228,10 @@ class PhoneFormFieldState extends FormFieldState<PhoneNumber> {
return padding;
}
}

enum _CountryButtonSlot {
prefix,
prefixIcon,
suffix,
suffixIcon,
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: phone_form_field
description: Flutter phone input integrated with flutter internationalization
version: 9.1.0
version: 9.1.1
homepage: https://github.com/cedvdb/phone_form_field

environment:
Expand Down

0 comments on commit b96ef68

Please sign in to comment.