LibPhonenumberTextFormatter constructor

LibPhonenumberTextFormatter({
  1. required CountryWithPhoneCode country,
  2. PhoneNumberType phoneNumberType = PhoneNumberType.mobile,
  3. PhoneNumberFormat phoneNumberFormat = PhoneNumberFormat.international,
  4. FutureOr onFormatFinished(
    1. String val
    )?,
  5. bool inputContainsCountryCode = false,
  6. int additionalDigits = 0,
  7. 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);
}