Skip to content

Commit

Permalink
Merge pull request #32 from netglade/fix/glade-input-asser
Browse files Browse the repository at this point in the history
Fix gladeinput assert
  • Loading branch information
tenhobi authored Feb 1, 2024
2 parents 2403374 + 3aa637e commit 0664943
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions glade_forms/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.3.1
- **[Fix]**: Fixed `GladeInput.create` assert to allow null for `value` and `initialValue` when input's type is nullable.

## 1.3.0
- **[Fix]**: When using `GladeInput.create`, passing only `value` ended up in UI vs model not being synced. Now that's fixed.
- **[Breaking]**: StringInput only works with `String` now.
Expand Down
2 changes: 1 addition & 1 deletion glade_forms/lib/src/core/glade_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class GladeInput<T> extends ChangeNotifier {
ValueTransform<T>? valueTransform,
DefaultTranslations? defaultTranslations,
}) {
assert(value != null || initialValue != null, 'At least one of value or initialValue must be set');
assert(value != null || initialValue != null || TypeHelper.typeIsNullable<T>(), 'If type is not nullable, at least one of value or initialValue must be set');

final validatorInstance = validator?.call(GladeValidator<T>()) ?? GladeValidator<T>().build();

Expand Down
2 changes: 2 additions & 0 deletions glade_forms/lib/src/core/type_helper.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class TypeHelper {
static bool typesEqual<T1, T2>() => T1 == T2;

static bool typeIsNullable<T>() => null is T;

static bool typeIsStringOrNullabeString<T>() => typesEqual<T, String>() || typesEqual<T, String?>();
}
2 changes: 1 addition & 1 deletion glade_forms/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: glade_forms
description: A universal way to define form validators with support of translations.
version: 1.3.0
version: 1.3.1
repository: https://github.com/netglade/glade_forms
issue_tracker: https://github.com/netglade/glade_forms/issues
screenshots:
Expand Down

0 comments on commit 0664943

Please sign in to comment.