How to pass List type data to params in flutter to call API?

Viewed 133

I have to Pass Data as Below to My Function to get Data.

{
 "page": "1",
 "pageSize": "10",
 "filters": [
   {
     "filterColumn": "status",
     "filterCondition": null,
     "filterDataType": null,
     "filterOperator": null,
     "filterValue": "In Progress"
   }
 ]
}

And below is my Function which call an API.

Future<Paging<CaseModel>> getTicketList(int page) async {
    User userData = DataManager.instance.getUser();
    Map<String, String> params = {"page": "$page", "pageSize": "10"};
    Map<String, String> headers = {"Authorization": userData.authToken!};
    var req = RestRequest(reqUrl: API_LEAD_LIST)
      ..reqMethod = RequestMethod.METHOD_POST
      ..contentType = ContentType.CONTENT_JSON
      ..params = params
      ..header = headers;
    Response res = await req.dioSend();
    Paging<CaseModel> paging = new Paging();
    paging.pageNumber = page + 1;
    int totalPage = res.data!["totalPages"];
    int currentPage = res.data!["currentPageNumber"];
    if (totalPage == currentPage) {
      paging.hasMore = false;
    } else if (currentPage < totalPage) {
      paging.hasMore = true;
    }
    paging.arrayList = CaseModel.fromArrayOfHashMap(res.data["dataList"]);
    return paging;
  }

So how can I pass the data in params to get data based on filters?

1 Answers

You need to create Map<String, dynamic> type param.

Example:

Map<String,dynamic>  param = {"page": "$page", "pageSize": "10", "filters":[
   {
     "filterColumn": "status",
     "filterCondition": null,
     "filterDataType": null,
     "filterOperator": null,
     "filterValue": "In Progress"
   }
 ]};

then call API.

Related