GrxPostalCodeUiModel.fromMap constructor

GrxPostalCodeUiModel.fromMap(
  1. Map<String, dynamic>? map
)

Implementation

factory GrxPostalCodeUiModel.fromMap(Map<String, dynamic>? map) {
  if (map == null) return const GrxPostalCodeUiModel();

  String? inputType;
  final inputTypeValue = map['inputType'] ?? map['input_type'];
  if (inputTypeValue is String) {
    final normalized = inputTypeValue.toLowerCase().trim();
    if (normalized == 'numeric' ||
        normalized == 'alphanumeric' ||
        normalized == 'text') {
      inputType = normalized;
    }
  }

  String? mask;
  final maskValue = map['mask'];
  if (maskValue is String && maskValue.isNotEmpty) {
    mask = maskValue;
  }

  int? maxLength;
  final maxLengthValue = map['maxLength'] ?? map['max_length'];
  if (maxLengthValue != null) {
    if (maxLengthValue is int) {
      maxLength = maxLengthValue > 0 ? maxLengthValue : null;
    } else if (maxLengthValue is num) {
      maxLength = maxLengthValue.toInt() > 0 ? maxLengthValue.toInt() : null;
    }
  }

  String? hint;
  final hintValue = map['hint'];
  if (hintValue is String && hintValue.isNotEmpty) {
    hint = hintValue;
  }

  String? format;
  final formatValue = map['format'];
  if (formatValue is String && formatValue.isNotEmpty) {
    format = formatValue;
  }

  return GrxPostalCodeUiModel(
    inputType: inputType,
    mask: mask,
    maxLength: maxLength,
    hint: hint,
    format: format,
  );
}