From 3aa637eb006d966a5d740c81660f71fffa7aa6d6 Mon Sep 17 00:00:00 2001 From: Honza Bittner Date: Thu, 1 Feb 2024 13:37:41 +0100 Subject: [PATCH] Fix gladeinput assert --- glade_forms/CHANGELOG.md | 3 +++ glade_forms/lib/src/core/glade_input.dart | 2 +- glade_forms/lib/src/core/type_helper.dart | 2 ++ glade_forms/pubspec.yaml | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/glade_forms/CHANGELOG.md b/glade_forms/CHANGELOG.md index f986910..a5c9b7e 100644 --- a/glade_forms/CHANGELOG.md +++ b/glade_forms/CHANGELOG.md @@ -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. diff --git a/glade_forms/lib/src/core/glade_input.dart b/glade_forms/lib/src/core/glade_input.dart index 2be90b4..5e09115 100644 --- a/glade_forms/lib/src/core/glade_input.dart +++ b/glade_forms/lib/src/core/glade_input.dart @@ -201,7 +201,7 @@ class GladeInput extends ChangeNotifier { ValueTransform? 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(), 'If type is not nullable, at least one of value or initialValue must be set'); final validatorInstance = validator?.call(GladeValidator()) ?? GladeValidator().build(); diff --git a/glade_forms/lib/src/core/type_helper.dart b/glade_forms/lib/src/core/type_helper.dart index 03b2a12..7647771 100644 --- a/glade_forms/lib/src/core/type_helper.dart +++ b/glade_forms/lib/src/core/type_helper.dart @@ -1,5 +1,7 @@ class TypeHelper { static bool typesEqual() => T1 == T2; + static bool typeIsNullable() => null is T; + static bool typeIsStringOrNullabeString() => typesEqual() || typesEqual(); } diff --git a/glade_forms/pubspec.yaml b/glade_forms/pubspec.yaml index 0abecd8..9a90c95 100644 --- a/glade_forms/pubspec.yaml +++ b/glade_forms/pubspec.yaml @@ -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: