Skip to content

Commit

Permalink
reformat national number on country changed
Browse files Browse the repository at this point in the history
  • Loading branch information
cedvdb committed Feb 5, 2024
1 parent 182e604 commit a9c447b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [9.0.2]
- reformat national number on country changed

## [9.0.1]
- unexport circle flags

Expand Down
16 changes: 12 additions & 4 deletions lib/src/phone_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PhoneController extends ChangeNotifier {
_value.nsn,
destinationCountry: isoCode,
);
_changeFormattedNationalNumber(_value.formatNsn());
notifyListeners();
}

Expand Down Expand Up @@ -58,13 +59,20 @@ class PhoneController extends ChangeNotifier {
_value = phoneNumber;
newFormattedText = phoneNumber.formatNsn();
}
_formattedNationalNumberController.value = TextEditingValue(
text: newFormattedText,
selection: _computeSelection(text, newFormattedText),
);
_changeFormattedNationalNumber(newFormattedText);
notifyListeners();
}

void _changeFormattedNationalNumber(String newFormattedText) {
if (newFormattedText != _formattedNationalNumberController.text) {
_formattedNationalNumberController.value = TextEditingValue(
text: newFormattedText,
selection: _computeSelection(
_formattedNationalNumberController.text, newFormattedText),
);
}
}

/// When the cursor is at the end of the text we need to preserve that.
/// Since there is formatting going on we need to explicitely do it.
/// We don't want to do it in the middle because the user might have
Expand Down
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.0.1
version: 9.0.2
homepage: https://github.com/cedvdb/phone_form_field

environment:
Expand Down

0 comments on commit a9c447b

Please sign in to comment.