I want to build a ListView with data from my website. I start my http request with a Void init state (if there is a better way pls tell me) And i request the array out of it in my Listview but the Listview doesnt recognice the array variable.
Does someone know how i have to transform this code so that i will get my array shown as a ListView?
Future senddata() async {
final response = await http.post(
"https://www.bumsbirne.php", body: {
"status": "0",
});
var datauser = json.decode(response.body);
print(datauser);
return datauser;
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
senddata();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Jo wenn das klappt"),
),
body: ListView.builder(
padding: const EdgeInsets.all(16.0),
itemCount: datauser == null ? 0 : datauser.length,
itemBuilder: (context, index) {
return _buildImageColumn(datauser[index]);
// return _buildRow(data[index]);
})
);
}
}
This is the Error: Error: The getter 'datauser' isn't defined for the class '_MyHomePageState'.
Update:
After using the answer i had this Problem: Type 'String' is not a subtype of type 'int' of 'index' Because of the formation of my json however i could fix it by using the method of this thread: Type 'String' is not a subtype of type 'int' of 'index'