'Unhandled Exception: Converting object to an encodable object failed: Instance of 'TextEditingController'
I got this error when I tried to send data to an API endpoint in Flutter. I don't seem to understand where the error is coming from.
Here is my data:
var data = {
'first_name': widget.first_name.toString(),
'last_name': widget.last_name.toString(),
'username': username.text,
'email': widget.email.toString(),
'mobile_number': widget.mobile_number.toString(),
'password': password.text,
'gender': gender,
'repeat_password': repeat_password.text,
'dob': dob,
'accepted_terms': 'on'
};
Solution 1:[1]
Here ,
If value contains objects that are not directly encodable to a JSON string (a value that is not a number, boolean, string, null, list or a map with string keys), the toEncodable function is used to convert it to an object that must be directly encodable.
const data = {};
final String jsonString = jsonEncode(data);
print(jsonString);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Manishyadav |
