LibPhonenumberTextFormatter constructor
LibPhonenumberTextFormatter({
- required CountryWithPhoneCode country,
- PhoneNumberType phoneNumberType = PhoneNumberType.mobile,
- PhoneNumberFormat phoneNumberFormat = PhoneNumberFormat.international,
- FutureOr onFormatFinished(
- String val
- bool inputContainsCountryCode = false,
- int additionalDigits = 0,
- bool shouldKeepCursorAtEndOfInput = true,
Implementation
LibPhonenumberTextFormatter({
required this.country,
this.phoneNumberType = PhoneNumberType.mobile,
this.phoneNumberFormat = PhoneNumberFormat.international,
this.onFormatFinished,
/// When true, mask will be applied assuming the input contains
/// a country code in it.
final bool inputContainsCountryCode = false,
/// Additional digits to include
this.additionalDigits = 0,
/// Force cursor the end of input when formatting.
this.shouldKeepCursorAtEndOfInput = true,
}) : countryData = CountryManager().countries {
var m = country.getPhoneMask(
format: phoneNumberFormat,
type: phoneNumberType,
removeCountryCodeFromMask: !inputContainsCountryCode,
);
/// Allow additional digits on the mask
if (additionalDigits > 0) {
m += List.filled(additionalDigits, '0')
.reduce((final a, final b) => a + b);
}
_mask = PhoneMask(m);
}