0

Basically I want to collect my API data in an array AND add new data to my array every time I'm calling my API, then use map function to construct my dynamic row...I hope you understood my problem.

My code, try to construct dynamic row by collecting data in an Array

 Future<void> GetTestFee() async {
var jsonResponse;
if (encTestId.isNotEmpty) {
  var response = await http.post(
      Uri.parse("http://getrbi.in/api/agtyi/GetTestFee"),
      body: ({
        'EncPartnerId': encLabId,
        'EncTestId': encTestId, 

      }));
  if (response.statusCode == 200) {
    print("Correct");
    print(response.body);
    jsonResponse = json.decode(response.body.toString());
    print(jsonResponse);
    getTestFeeObj=GetTestFeeMap.fromJson(jsonResponse);

  } else {
    throw Exception("Faild to fetch");
  }
} else {
  throw Exception("Faild to fetch");
}
//throw Exception("Faild to fetch");
return GetTestFee();

}

JSON resresponse

      {
  "EncPartnerId": "LEuT1eIlpLiuiiyAAkZme3wpQ==",
  "EncTestId": "U4exk+vfMGrn7cjNUa/kji==",
  "Fee": "100",
  "DiscountedFee": "80",
  "BookingFee": "50"
}

1 Answer 1

1

You can add your model to list:

List<GetTestFeeMap> reponseModel =[]

And after getting you response add it into list

var response = await http.post(
      Uri.parse("http://ytyttiiiuiu.in/api/medboapi/GetTestFee"),
      body: ({
        'EncPartnerId': encLabId, // can use for test run "LEuT1eIlpLEMAAkZme3wpQ==",
        'EncTestId': encTestId,  // "U4exk+vfMGrn7cjNUa/PBw=="

      }));
  if (response.statusCode == 200) {
print("Correct");
print(response.body);
jsonResponse = json.decode(response.body.toString());
print(jsonResponse);
getTestFeeObj=GetTestFeeMap.fromJson(jsonResponse);
 reponseModel.add(getTestFeeObj)

I hope I undrestand right.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.