flutter
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);
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?
Similar Posts