diff --git a/glade_forms/CHANGELOG.md b/glade_forms/CHANGELOG.md index 0666798..d798e5c 100644 --- a/glade_forms/CHANGELOG.md +++ b/glade_forms/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.5.0 +- **[Feat]**: Add `updateWhenNotNull` to support shorthand syntax for Widgets with nullable type parameter. + ## 1.4.0 - **[Feat]**: Support non-data-holding inputs to enable "view" inputs. - **[Feat]**: Add the `shouldTriggerOnChange` parameter to `updateValue` so one can opt-out from `onChange` callback being triggered. diff --git a/glade_forms/lib/src/core/glade_input.dart b/glade_forms/lib/src/core/glade_input.dart index 038d4af..292eabc 100644 --- a/glade_forms/lib/src/core/glade_input.dart +++ b/glade_forms/lib/src/core/glade_input.dart @@ -450,6 +450,17 @@ class GladeInput extends ChangeNotifier { void updateValue(T value, {bool shouldTriggerOnChange = true}) => _setValue(value, shouldTriggerOnChange: shouldTriggerOnChange); + /// Used as shorthand for field setter. + /// + /// If `T` is non-nullable type and provided value is `null`, update is **not invoked**. + /// + /// When [shouldTriggerOnChange] is set to false, the `onChange` callback will not be called. + void updateValueWhenNotNull(T? value, {bool shouldTriggerOnChange = true}) { + if (value == null) return; + + return _setValue(value, shouldTriggerOnChange: shouldTriggerOnChange); + } + /// Resets input into pure state. /// /// Allows to sets new initialValue and value if needed. diff --git a/glade_forms/pubspec.yaml b/glade_forms/pubspec.yaml index a8fb58b..871f2cc 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.4.0 +version: 1.5.0 repository: https://github.com/netglade/glade_forms issue_tracker: https://github.com/netglade/glade_forms/issues screenshots: