Reputation: 345
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"
}
Upvotes: 0
Views: 638
Reputation: 5942
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.
Upvotes: 1