How to preprocess the initialValue?
valueTransformer: (value) => int.tryParse(value) will convert the value to a number, but next time when I open the form the initialValue is a number, this will lead an error: Expected a value of type 'String?', but got one of type 'int'。
Is there an initialValueTransformer or some way I can use to convert the initialValue to a String that the FormBuilderTextFieldexpected?
Just use the .toString() method.
int numbers = 12345;
initialValue: numbers.toString();
@jaxnz
Thanks, but .toString() is not what I want. If the valueTransformer is valueTransformer: (value) => int.parse(value) /100, so I need something can perform the reverse process initialValueTransformer: (value) => (value * 100).toString(), not only just .toString(). But It seems that there is no such property.
@jaxnz Thanks, but
.toString()is not what I want. If the valueTransformer isvalueTransformer: (value) => int.parse(value) /100, so I need something can perform the reverse processinitialValueTransformer: (value) => (value * 100).toString(), not only just.toString(). But It seems that there is no such property.
it would be helpful and clean to have such property ,
as a workaround , in your controller transform all integers to strings before you set initialValue ,
this package should have a FormBuilderNumberField out of the box , as it is very common .