validType static method

PhoneNumberInputValidator validType(
  1. BuildContext context,
  2. PhoneNumberType expectedType, {
  3. String? errorText,
})

Implementation

static PhoneNumberInputValidator validType(
  BuildContext context,

  /// expected phonetype
  PhoneNumberType expectedType, {
  /// custom error message
  String? errorText,
}) {
  return (PhoneNumber? valueCandidate) {
    if (valueCandidate != null &&
        valueCandidate.nsn.isNotEmpty &&
        !valueCandidate.isValid(type: expectedType)) {
      if (expectedType == PhoneNumberType.mobile) {
        return errorText ??
            PhoneFieldLocalization.of(context).invalidMobilePhoneNumber;
      } else if (expectedType == PhoneNumberType.fixedLine) {
        return errorText ??
            PhoneFieldLocalization.of(context).invalidFixedLinePhoneNumber;
      }
      return errorText ??
          PhoneFieldLocalization.of(context).invalidPhoneNumber;
    }
    return null;
  };
}