Skip to content

Commit

Permalink
Revert to isRequired argument instead of factory constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
petrnymsa committed Jan 29, 2025
1 parent a14e487 commit 83a7ff8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 75 deletions.
5 changes: 4 additions & 1 deletion glade_forms/lib/src/core/input/glade_bool_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ class GladeBoolInput extends GladeInput<bool> {
super.valueTransform,
super.defaultTranslations,
super.trackUnchanged = true,
bool isRequired = true,
}) : super.internalCreate(
stringToValueConverter: stringToValueConverter ?? GladeTypeConverters.boolConverter,
validatorInstance: validator?.call(GladeValidator()) ?? GladeValidator<bool>().build(),
validatorInstance: isRequired
? (validator?.call(GladeValidator<bool>()..notNull()) ?? (GladeValidator<bool>()..notNull()).build())
: (validator?.call(GladeValidator()) ?? GladeValidator<bool>().build()),
);
}
34 changes: 9 additions & 25 deletions glade_forms/lib/src/core/input/glade_date_time_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ class GladeDateTimeInput extends GladeInput<DateTime> {
super.valueTransform,
super.defaultTranslations,
super.trackUnchanged = true,
bool isRequired = true,
}) : super.internalCreate(
stringToValueConverter: stringToValueConverter ?? GladeTypeConverters.dateTimeIso8601,
validatorInstance: validator?.call(DateTimeValidator()) ?? DateTimeValidator().build(),
validatorInstance: isRequired
? (validator?.call(DateTimeValidator()..notNull()) ?? (DateTimeValidator()..notNull()).build())
: (validator?.call(DateTimeValidator()) ?? DateTimeValidator().build()),
);
}

Expand All @@ -47,31 +50,12 @@ class GladeDateTimeInputNullable extends GladeInput<DateTime?> {
super.valueTransform,
super.defaultTranslations,
super.trackUnchanged = true,
bool isRquired = false,
}) : super.internalCreate(
stringToValueConverter: stringToValueConverter ?? GladeTypeConverters.dateTimeIso8601Nullable,
validatorInstance: validator?.call(DateTimeValidatorNullable()) ?? DateTimeValidatorNullable().build(),
);

GladeDateTimeInputNullable.required({
super.inputKey,
super.value,
super.initialValue,
DateTimeValidatorFactoryNullable? validator,
super.isPure,
super.translateError,
super.valueComparator,
StringToTypeConverter<DateTime?>? stringToValueConverter,
super.dependencies,
super.onChange,
super.onDependencyChange,
super.textEditingController,
super.useTextEditingController = false,
super.valueTransform,
super.defaultTranslations,
super.trackUnchanged = true,
}) : super.internalCreate(
stringToValueConverter: stringToValueConverter ?? GladeTypeConverters.dateTimeIso8601Nullable,
validatorInstance: validator?.call(DateTimeValidatorNullable()..notNull()) ??
(DateTimeValidatorNullable()..notNull()).build(),
validatorInstance: isRquired
? (validator?.call(DateTimeValidatorNullable()..notNull()) ??
(DateTimeValidatorNullable()..notNull()).build())
: (validator?.call(DateTimeValidatorNullable()) ?? DateTimeValidatorNullable().build()),
);
}
33 changes: 8 additions & 25 deletions glade_forms/lib/src/core/input/glade_int_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ class GladeIntInput extends GladeInput<int> {
super.valueTransform,
super.defaultTranslations,
super.trackUnchanged = true,
bool isRequired = true,
}) : super.internalCreate(
stringToValueConverter: stringToValueConverter ?? GladeTypeConverters.intConverter,
validatorInstance: validator?.call(IntValidator()) ?? IntValidator().build(),
validatorInstance: isRequired
? (validator?.call(IntValidator()..notNull()) ?? (IntValidator()..notNull()).build())
: (validator?.call(IntValidator()) ?? IntValidator().build()),
);
}

Expand All @@ -47,31 +50,11 @@ class GladeIntInputNullable extends GladeInput<int?> {
super.valueTransform,
super.defaultTranslations,
super.trackUnchanged = true,
bool isRequired = false,
}) : super.internalCreate(
stringToValueConverter: stringToValueConverter ?? GladeTypeConverters.intConverterNullable,
validatorInstance: validator?.call(IntValidatorNullable()) ?? IntValidatorNullable().build(),
);

GladeIntInputNullable.required({
super.inputKey,
super.value,
super.initialValue,
IntValidatorFactoryNullable? validator,
super.isPure,
super.translateError,
super.valueComparator,
StringToTypeConverter<int?>? stringToValueConverter,
super.dependencies,
super.onChange,
super.onDependencyChange,
super.textEditingController,
super.useTextEditingController = false,
super.valueTransform,
super.defaultTranslations,
super.trackUnchanged = true,
}) : super.internalCreate(
stringToValueConverter: stringToValueConverter ?? GladeTypeConverters.intConverterNullable,
validatorInstance:
validator?.call(IntValidatorNullable()..notNull()) ?? (IntValidatorNullable()..notNull()).build(),
validatorInstance: isRequired
? (validator?.call(IntValidatorNullable()..notNull()) ?? (IntValidatorNullable()..notNull()).build())
: (validator?.call(IntValidatorNullable()) ?? IntValidatorNullable().build()),
);
}
28 changes: 4 additions & 24 deletions glade_forms/lib/src/core/input/glade_string_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,12 @@ class GladeStringInput extends GladeInput<String> {
super.valueTransform,
super.defaultTranslations,
super.trackUnchanged = true,
bool isRequired = true,
}) : super.internalCreate(
value: value ?? initialValue ?? '',
initialValue: initialValue ?? '',
validatorInstance: validator?.call(StringValidator()) ?? StringValidator().build(),
);

GladeStringInput.required({
super.inputKey,
String? value,
String? initialValue,
StringValidatorFactory? validator,
super.isPure,
super.translateError,
super.valueComparator,
super.stringToValueConverter,
super.dependencies,
super.onChange,
super.onDependencyChange,
super.textEditingController,
super.useTextEditingController = true,
super.valueTransform,
super.defaultTranslations,
super.trackUnchanged = true,
}) : super.internalCreate(
value: value ?? initialValue ?? '',
initialValue: initialValue ?? '',
validatorInstance: validator?.call(StringValidator()..notEmpty()) ?? (StringValidator()..notEmpty()).build(),
validatorInstance: isRequired
? (validator?.call(StringValidator()..notNull()) ?? (StringValidator()..notNull()).build())
: (validator?.call(StringValidator()) ?? StringValidator().build()),
);
}

0 comments on commit 83a7ff8

Please sign in to comment.