I am trying to show the data from database to Flutter. I am able to get the data but don't know how can i show it in Flutter. Single data i can show but getting hard time presenting multiple data.
I am using DIO plugin for HTTP requests.
Here is the code.
Future getData() async{
try{
dtguid ='34';
var bodyss = { "uid" : dtgUid, "deviceid": deviceid};
Response<Map> responsess =
await Dio().post("http://192.168.100.4:8080/sampleapp/get-followingdata.php", data: bodyss,);
Map responseBody = response.data;
if(responseBodys['success'] == false){
_showSnackBar(context,responseBody['errors']['inputuid'],Colors.redAccent);
this.setState((){
_inProcess = false;
});
}else{
print(responseBody['success']);
totalcount = responseBody['count'];
this.setState((){
_inProcess = false;
});
}
}catch(e){
print("Exception Caught: $e");
}
}
Here is the Widget where i need to show this data.
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Test',// schoolLists[index]['name'],
style: TextStyle(
color: primary,
fontWeight: FontWeight.bold,
fontSize: 18),
),
SizedBox(
height: 6,
),
Row(
children: <Widget>[
Icon(
Icons.location_on,
color: secondary,
size: 20,
),
SizedBox(
width: 5,
),
Text(
'Earth',//schoolLists[index]['location'],
style: TextStyle(
color: primary, fontSize: 13, letterSpacing: .3)),
],
),
SizedBox(
height: 6,
),
Row(
children: <Widget>[
Icon(
Icons.school,
color: secondary,
size: 20,
),
SizedBox(
width: 5,
),
Text(
'Some Data',
//schoolLists[index]['type'],
style: TextStyle(
color: primary, fontSize: 13, letterSpacing: .3)),
],
),
],
),
)
For testing purpose i tried with some hardcoded data schoolLists that is working but i don't know how can i show the data from http request.
Sample Data.
{"errors":[],
"content":[{"uid":34,"age":35,"name":"Test User 1","country":"India"},
{"uid":34,"age":37,"name":"Test User 2","country":"India"},
{"uid":34,"age":36,"name":"Test User 3","country":"India"}],
"success":true}
I need to show name and country to the widget. In place of this test value.
Text(
'Test',// schoolLists[index]['name'],
style: TextStyle(
color: primary,
fontWeight: FontWeight.bold,
fontSize: 18),
),
Later on i will try to work on Lazyload. Unfortunatly, i am not able to show the data so, didn't asked about the lazyload.
To be honest i am learning Flutter. I don't have much experience in it.
getData()..?