changeNationalNumber method
dynamic
changeNationalNumber(
- String? text
)
Implementation
changeNationalNumber(String? text) {
text = text ?? '';
var newFormattedText = text;
// if starts with + then we parse the whole number
final startsWithPlus =
text.startsWith(RegExp('[${AllowedCharacters.plus}]'));
if (startsWithPlus) {
final phoneNumber = _tryParseWithPlus(text);
// if we could parse the phone number we can change the value inside
// the national number field to remove the "+ country dial code"
if (phoneNumber != null) {
_value = phoneNumber;
newFormattedText = _value.formatNsn();
}
} else {
final phoneNumber = PhoneNumber.parse(
text,
destinationCountry: _value.isoCode,
);
_value = phoneNumber;
newFormattedText = phoneNumber.formatNsn();
}
_changeFormattedNationalNumber(newFormattedText);
notifyListeners();
}