Toujo
Toujo

Reputation: 335

How to pass ArrayList item to body of http request (post) in Flutter?

I hava a ArrayList where storing data from my API List<GetTestFeeMap> reponseArray =[]; // Storing API response

Then Adding data to my ArraylistreponseArray.add(getTestFeeObj!);

Now trying to get each encTestId. But its just give the first value only (obviously). I want to pass all the encTestId(to http body) which is possibly in my List (separated by comma.)

 getTestFeeObj=GetTestFeeMap.fromJson(jsonResponse);
              for (var i = 0; i < reponseArray.length; i++) {
                    eNcTestIdInList=(reponseArray[i].encTestId)!;
                    }

Then passing to my body of http request

  body: ({

        'EncDoctorId'   : eNcTestIdInList,
     )}

Example of correct body in postman

{
"EncDoctorId": "I3uXyzcuDZf21SSe5fHnSQ==,7Ch2aVnhokZtRWyJtuDA/A==",   // 2 encTestId 
}
        

I hope you understood my problem.

Upvotes: 1

Views: 1035

Answers (1)

Huthaifa Muayyad
Huthaifa Muayyad

Reputation: 12353

Use this:

eNcTestIdInList+=(reponseArray[i].encTestId);
if (i < reponseArray.length -1) eNcTestIdInList+= ",";

Upvotes: 1

Related Questions