List userdata = [];
Future<void> getStudentData() async {
String uri = "http://localhost/dashboard/demo/view.php";
try {
var response = await http.get(Uri.parse(uri));
setState(() {
userdata = jsonDecode(response.body);
});
} catch (e) {
print(e);
}
}
@override
void initState() {
super.initState();
getStudentData();
}
Column(
children: userdata.map((user) {
return Column(
children: <Widget>[
ElevatedButton(
onPressed: () {
},
child: Container(
child: Container(
margin: EdgeInsets.only(top: 10),
child: Column(
children: [
Text(
user["name"],
style: TextStyle(
fontSize: 20, color: Colors.white),
textAlign: TextAlign.center,
),
Text(
user["university"],
style: TextStyle(
fontSize: 20, color: Colors.white),
textAlign: TextAlign.center,
),
Text(
user["phone"],
style: TextStyle(
fontSize: 20, color: Colors.white),
textAlign: TextAlign.center,
),
],
),
),
),
)
],
);
}).toList(),
)
Hello, I tried with this code to fetch data from php API to flutter app and don’t print any thing the uri is correct it’s working successfully 100% on insert data
I Tried to delete setstate and tried alot of things but no new don’t print anything from database.