Flutter:显示来自Rest API的数据

我试图显示从数据库到Flutter的数据。 我能够获取数据,但不知道如何在Flutter中显示数据。我可以显示单个数据,但是很难呈现多个数据。

我正在将DIO插件用于HTTP请求。

这是代码。

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");
    }

  } 

这是我需要显示此数据的小部件。

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.

样本数据。

{"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}
评论