I need to decode the data I receive as utf8. The codes are like this
Future<Products> Get Product() async {
var response = await http.get(url);
var decodedJson = json.decode(response.body);
products = Products.fromJson(decodedJson);
return products;
}
I tried the solutions I saw. One of them told me to do it like this
var response = await http.get(url,headers: {'Content-Type': 'application/json'});
var decodedJson = json.decode(utf8.decode(response.bodyBytes));
When I do this, I get the following
errorException has occurred.
FormatException (FormatException: Missing extension byte (at offset 554))
And it's look like 
I had the same problem and solved it by setting Character Encoding on the Back-End side of my application.
This can be done by appending the Content-Type Header like this:
Content-Type: application/json;charset=UTF-8
There are different ways to achieve this depending on your Framework/Implementation.
Unfortunately, this answer is not suitable for Flutter per se.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With