get method

Future get(
  1. String url
)

Implementation

Future<dynamic> get(String url) async {
  return http
      .get(Uri.parse(url))
      .then((http.Response response) {
        final String res = response.body;
        final int statusCode = response.statusCode;
        if (statusCode < 200 || statusCode >= 400) {
          throw Exception(_decoder.convert(res)['error']['message']);
        }
        return res;
      })
      .catchError((onError) {
        if (onError.toString().toLowerCase().contains("socket")) {
          throw Exception("Server timeout");
        } else {
          throw Exception(onError.toString().replaceAll("Exception:", ""));
        }
      })
      .timeout(const Duration(seconds: 10))
      .catchError((onError) {
        if (onError.toString().toLowerCase().contains("timeout")) {
          throw Exception("Server timeout");
        } else {
          throw Exception(onError.toString().replaceAll("Exception:", ""));
        }
      });
}