-
-
Notifications
You must be signed in to change notification settings - Fork 561
valueTransformer empty to null value #1286
-
I need the field to be null when it's empty like below:
{ name: null }
So, im using valueTransformer as follows:
... name: 'name', valueTransformer: (value) { if (value == null || value.trim().isEmpty) { return null; } return value; }, ...
But, im still getting:
{ name: "" }
Is there a way i can achieve it?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 2 replies
-
I have the same Problem here...
valueTransformer: (String? value) { if (value == null) return null; return double.tryParse(value); },
but the field is always exact the data, were i have written into the field.
I read with
if (formKey.currentState!.saveAndValidate()) { dynamic data = formKey.currentState?.value;
Beta Was this translation helpful? Give feedback.
All reactions
-
Or is it possible to get the transformed values this way?
formKey.currentState!.getTransformedValue('quantity')
Can't find documentation about that.
Beta Was this translation helpful? Give feedback.
All reactions
-
Ok i see - the Problem is the valueTransformer implementation.
If i return a null the original value will be used. A Bug in my opinion, because null can be a valid value.
dynamic get transformedValue => widget.valueTransformer?.call(value) ?? value;
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1