Skip to content

Commit

Permalink
Add updateWhenNotNull
Browse files Browse the repository at this point in the history
  • Loading branch information
petrnymsa committed Mar 13, 2024
1 parent 1582942 commit a7f64b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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.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.
Expand Down
11 changes: 11 additions & 0 deletions glade_forms/lib/src/core/glade_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,17 @@ class GladeInput<T> 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.
Expand Down
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.4.0
version: 1.5.0
repository: https://github.com/netglade/glade_forms
issue_tracker: https://github.com/netglade/glade_forms/issues
screenshots:
Expand Down

0 comments on commit a7f64b3

Please sign in to comment.