getPhoneMask method
String
getPhoneMask({
- required PhoneNumberFormat format,
- required PhoneNumberType type,
- bool removeCountryCodeFromMask = false,
Get the phone mask based on number type and format.
When removeCountryCodeFromMask
is true then the resulting mask
will not contain the phone code. This is useful for real-time formatting
with LibPhonenumberTextFormatter where the user might be entering a phone
number without the country code in it but we still want to format it accordingly.
Implementation
String getPhoneMask({
required final PhoneNumberFormat format,
required final PhoneNumberType type,
final bool removeCountryCodeFromMask = false,
}) {
late String returnMask;
if (type == PhoneNumberType.mobile) {
if (format == PhoneNumberFormat.international) {
returnMask = phoneMaskMobileInternational;
} else {
returnMask = phoneMaskMobileNational;
}
} else {
if (format == PhoneNumberFormat.international) {
returnMask = phoneMaskFixedLineInternational;
} else {
returnMask = phoneMaskFixedLineNational;
}
}
/// If we want to get the mask without the country code, strip
/// out the country code from the mask now.
if (removeCountryCodeFromMask) {
/// Return the mask after the country code and 2 characters,
/// one for the leading + and the other for the space between
/// country code and number.
returnMask = returnMask.substring(phoneCode.length + 2);
}
return returnMask;
}