Flutter Dio post an object with array Flutter Dio post an object with array dart dart

Flutter Dio post an object with array


It all depends on how the API expects it. I would suggest trying to encode it as JSON.

var params =  {  "item": "itemx",  "options": jsonEncode([1,2,3]),};

But sending complex data in query parameters isn't always that easy. Since you are using POST anyway, maybe send a JSON object as body instead of using query parameters.

var params =  {  "item": "itemx",  "options": [1,2,3],}; ...Response response = await _dio.post(getAddToCartURL,  options: Options(headers: {    HttpHeaders.contentTypeHeader: "application/json",  }),  data: jsonEncode(params),);