getDataFromUrl static method

Future<String?> getDataFromUrl(
  1. String url, [
  2. Map<String, String?>? headers
])

Request data from given uri along with headers. May return null if resource is not available or on error.

Implementation

static Future<String?> getDataFromUrl(
  String url, [
  Map<String, String?>? headers,
]) async {
  try {
    final request = await _httpClient.getUrl(Uri.parse(url));
    if (headers != null) {
      headers.forEach((name, value) => request.headers.add(name, value!));
    }

    final response = await request.close();
    var data = "";
    await response.transform(const Utf8Decoder()).listen((content) {
      data += content.toString();
    }).asFuture<String?>();

    return data;
  } catch (exception) {
    PipFlutterPlayerUtils.log("GetDataFromUrl failed: $exception");
    return null;
  }
}