Please help me... I just tried this code:
**try {
final response = http.get(url); // Giving error here
final extractedData = json.decode(response.body);
} catch (error) {
throw error;
}**
Error Message "message": "The getter 'body' isn't defined for the type 'Future'.\nTry importing the library that defines 'body', correcting the name to the name of an existing getter, or defining a getter or field named 'body'.",
try {
final response = await http.get(url);
final extractedData = json.decode(response.body);
} catch (error) {
throw error;
}
You get this error because get()
returns a Future<Response>
, meaning it is asynchronous so you need to use async/await to be able to get the Response
object and then call body
.
Please check the following: