Issue
I’ve tried to insert my html text to display on my flutter apps, I’ve got some warning.
But the result was good.
My Code:
'''
final response = await http.get(
Uri.parse(BaseUrl.apiBaseUrl + 'myapi'),
headers: {HttpHeaders.authorizationHeader: "Bearer " + token});
final result = json.decode(response.body);
'''
How I fix this warning?
Result:
I/flutter ( 8104): FormatException: Unexpected character (at character 1)
I/flutter ( 8104):
I/flutter ( 8104): ^
I/flutter ( 8104): FormatException: Unexpected character (at character 1)
I/flutter ( 8104):
I/flutter ( 8104): ^
Solution
The problem is on final result = json.decode(response.body);
In your response body, you are either getting a null or a non JSON format. That’s why when your code is decoding it into JSON there is an exception.
Answered By – Aloysius Samuel
Answer Checked By – David Marino (FlutterFixes Volunteer)