Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

valueTransformer empty to null value #1286

Unanswered
marco-origam asked this question in Q&A
Discussion options

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?

You must be logged in to vote

Replies: 1 comment 2 replies

Comment options

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;
You must be logged in to vote
2 replies
Comment options

Or is it possible to get the transformed values this way?
formKey.currentState!.getTransformedValue('quantity')
Can't find documentation about that.

Comment options

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /