get function

Future<Map<String, dynamic>> get(
  1. Uri url
)

This function retrieves data from the specified URL and returns a JSON object. If the response is null, it returns an error object with "error: true" field. Otherwise, it returns an object with "error: false" field and the response data.

Parameters:

  • url: The URL to retrieve data from.

Returns:

  • A Future object that will eventually resolve to a Map object.

Implementation

Future<Map<String, dynamic>> get(Uri url) async {
  try {
    final HttpClientRequest req = await HttpClient().getUrl(url);
    final HttpClientResponse res = await req.close();
    final responseBody = await res.transform(utf8.decoder).join();
    final responseJson = jsonDecode(responseBody) as Map<String, dynamic>;
    return {'error': false, ...responseJson};
  } catch (e) {
    return {'error': true, 'errorData': e};
  }
}