I am trying to fetch data from an API. I got the error 'type List is not a subtype of Map. I am new to this and didn't understand where I am making mistake.
This is my fetch post function:
Future<Post> fetchPost() async {
final response = await http.get('http://starlord.hackerearth.com/beercraft');
if (response.statusCode == 200) {
return Post.fromJson(json.decode(response.body));
} else {
throw Exception('Failed to load post');
}
}
In my home screen I am using a FutureBuilder like this:
final Future<Post> post;
HomeScreen({Key key, this.post}) : super(key: key);
FutureBuilder<Post>(
future: post,
builder: (context, result) {
if (result.hasData) {
return ListView.builder(
itemBuilder: (context, index){
return cartItemComponent(result.data.name, result.data.abv, result.data.ounces);
},
);
} else if (result.hasError) {
return Text("${result.error}");
}
// By default, show a loading spinner.
return CircularProgressIndicator();
},
How can I resolve this error? Thanks in advance.