Skip to content

Commit

Permalink
add downloadfile method in HttpUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno David da S. Almeida committed Jan 8, 2024
1 parent 8d65fd8 commit c2bfe91
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/utils/http_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ class HttpUtils {
],
);

static Future<HttpResponse> downloadFile(
String url, {
Map<String, String>? headers,
bool cached = false,
}) async {
return _reqJson("download", url, headers: headers, cached: cached);
}

static Future<HttpResponse> getJson(
String url, {
Map<String, String>? headers,
bool cached = false,
bool hasLog = false,
}) async {
return _reqJson("get", url,
headers: headers, cached: cached, hasLog: hasLog);
return _reqJson("get", url, headers: headers, cached: cached, hasLog: hasLog);
}

static Future<HttpResponse> postJson(
Expand All @@ -44,8 +51,7 @@ class HttpUtils {
bool cached = false,
bool hasLog = false,
}) async {
return _reqJson("post", url,
json: json, headers: headers, cached: cached, hasLog: hasLog);
return _reqJson("post", url, json: json, headers: headers, cached: cached, hasLog: hasLog);
}

static Future<HttpResponse> putJson(
Expand All @@ -55,8 +61,7 @@ class HttpUtils {
bool cached = false,
bool hasLog = false,
}) async {
return _reqJson("put", url,
json: json, headers: headers, cached: cached, hasLog: hasLog);
return _reqJson("put", url, json: json, headers: headers, cached: cached, hasLog: hasLog);
}

static Future<HttpResponse> deleteJson(
Expand All @@ -66,8 +71,7 @@ class HttpUtils {
bool cached = false,
bool hasLog = false,
}) async {
return _reqJson("delete", url,
json: json, headers: headers, cached: cached, hasLog: hasLog);
return _reqJson("delete", url, json: json, headers: headers, cached: cached, hasLog: hasLog);
}

static Future<HttpResponse> postFile(
Expand All @@ -76,8 +80,7 @@ class HttpUtils {
String filename, {
Map<String, String>? headers,
}) async {
return _reqJson("upload", url,
headers: headers, bytes: bytes, filename: filename);
return _reqJson("upload", url, headers: headers, bytes: bytes, filename: filename);
}

static Future<HttpResponse> postFiles(
Expand Down Expand Up @@ -148,8 +151,7 @@ class HttpUtils {
cachedBody = await ls.getString(cacheKeyBody);
String? status = await ls.getString(cacheKeyStatus);
if (status != null) {
cachedStatus =
int.parse(await ls.getString("httpreq-$reqHash-status") ?? "0");
cachedStatus = int.parse(await ls.getString("httpreq-$reqHash-status") ?? "0");
}
String? etag = await ls.getString(cacheKeyEtag);

Expand Down Expand Up @@ -179,9 +181,7 @@ class HttpUtils {
response = await http.Response.fromStream(await request.send());
} else {
if (method == "get") {
response = hasLog
? await _httpClient.get(Uri.parse(url), headers: headers)
: await http.get(Uri.parse(url), headers: headers);
response = hasLog ? await _httpClient.get(Uri.parse(url), headers: headers) : await http.get(Uri.parse(url), headers: headers);
} else if (method == "delete") {
response = hasLog
? await _httpClient.delete(
Expand Down

0 comments on commit c2bfe91

Please sign in to comment.