开发者

Flutter FormBuilding initial values and DateTime jsonEncode problem

I am using the formBuilder package to design a form for user to fill in, but I got 2 problems:

  1. I set initialValues for form fields, but when I submit, formValues contains nothing, but if I change the value a little bit on the UI, formValues shows 开发者_如何学编程correct info.

  2. if there is a DateTimePicker in the form, jsonEncode returns error: Converting object to an encodable object failed: Instance of 'DateTime'

Please help.

formValues['expirydate'] = formValues['expirydate'].toIso8601String();

and this seem not work either


You can't encode a DateTime object with the jsonEncode() method. Instead, you must convert it to a string or a number before encoding. For example:

String dateString = formValues['expirydate'].toIso8601String(); 
String encodedString = jsonEncode(dateString);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜