Search code snippets, questions, articles...

Send a Map in query parameter of http request in Flutter

To send Map data in query parameters of an HTTP request in Dart or Flutter, you can use the code examples explained here.
import 'dart:convert';

// map data
var myMap = {
    'id': [1, 2, 3],
    'names': ['John', 'Rick', 'Carl']
}

// create url with map data in query string
Uri url = Uri.http(
    'domain.com',
    '/endpoint',
    {
      'mapData': jsonEncode(myMap),
    },
);
  
// Print the url
print(url);
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

In the above code example, we have created a Map variable "myMap" that contains multiple key values. We want to send this map in the query parameter of our dart HTTP request. We are sending this map data in the request by using the jsonEncode() function and passing this map as a parameter in this function.

Was this helpful?
0 Comments