Params.fromJson constructor

Params.fromJson(
  1. dynamic input
)

Implementation

Params.fromJson(dynamic input) {
  try {
    if (input is! Map<String, dynamic> && input is! Map<dynamic, dynamic>) {
      throw FormatException("Expected Map<String, dynamic>, got ${input.runtimeType}");
    }

    length = DtoCheck.checkNullableInt(input['length'], 'length');
    minAllowed = DtoCheck.checkNullableInt(input['minAllowed'], 'minAllowed');
    maxAllowed = DtoCheck.checkMax(input['max']);
    isMultiple = DtoCheck.checkNullableBool(input['isMultiple'], 'isMultiple') ?? false;
    mandatory = input['mandatory'] == null ? false : DtoCheck.checkNullableBool(input['mandatory'], 'mandatory') ?? false;

    displayMode = input['displayMode'] is String ? DisplayModeUtils.displayModeFromString(input['displayMode']) : (input['displayMode'] == null ? null : throw const FormatException("Invalid type for 'displayMode'"));

    selectPlusValueType = input['selectPlusValueType'] is String ? SelectPlusValueModeUtils.valueFromString(input['selectPlusValueType']) : (input['selectPlusValueType'] == null ? null : throw const FormatException("Invalid type for 'selectPlusValueType'"));

    unit = DtoCheck.checkNullableString(input['unit'], 'unit');
    placeholder = DtoCheck.checkNullableString(input['placeholder'], 'placeholder');
    minimumInputLines = DtoCheck.checkNullableInt(input['minimumInputLines'], 'minimumInputLines');

    description = DtoCheck.checkNullableString(input['description'], 'description');
    imgUrl = DtoCheck.checkNullableString(input['imgUrl'], 'imgUrl');
    imgDescription = DtoCheck.checkNullableString(input['imgDescription'], 'imgDescription');
    minValueLabel = DtoCheck.checkNullableString(input['minValueLabel'], 'minValueLabel');
    maxValueLabel = DtoCheck.checkNullableString(input['maxValueLabel'], 'maxValueLabel');

    nullBoolLabel = DtoCheck.checkNullableString(input['nullBoolLabel'], 'nullBoolLabel');
    falseBoolLabel = DtoCheck.checkNullableString(input['falseBoolLabel'], 'falseBoolLabel');
    trueBoolLabel = DtoCheck.checkNullableString(input['trueBoolLabel'], 'trueBoolLabel');

    selectorDisplayMode = DtoCheck.checkNullableString(input['selectorDisplayMode'], 'selectorDisplayMode');
    ratingDisplayMode = DtoCheck.checkNullableString(input['ratingDisplayMode'], 'ratingDisplayMode');

    hasOtherOption = DtoCheck.checkNullableBool(input['hasOtherOption'], 'hasOtherOption');

  } catch (e, s) {
    if (kDebugMode) {
      print('❌ Failed to parse Params: $e');
      print('📜 trace: $s');
    }
    DtoCheck.catchFormatExecption(e, s: s);
    rethrow;
  }
}