Hey, will Daten von meiner erstellten API ausgeben in meiner App.
Code:
fetchData() async {
final response = await http.get(Uri.parse('http://localhost/list.json'));
return json.decode(response.body);
}
FutureBuilder(
future: fetchData(),
builder: (BuildContext context, AsyncSnapshot snapshot){
if(snapshot.hasError){
return Center(
child:Text("Error"),
);
}
if(snapshot.hasData){
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index){
return Row(
children: [
Expanded(
child: Container(
child: Column(
children: [
Text(snapshot.data[index]['id']),
SizedBox(height: 10,),
Text(snapshot.data[index]['name']),
],
),
),
),
],
);
});
}
return Center(child: CircularProgressIndicator(),);
},
),
Jedoch bekomm ich als Ausgabe "Error". Woran kann das liegen? Die API kann ich mit Postmann abfragen.