From b044c342315488a0f938872e4c7a305413548131 Mon Sep 17 00:00:00 2001 From: MohammadTaha Basiri Date: Tue, 18 Jan 2022 18:17:23 +0330 Subject: [PATCH] D1APP-22 service updates --- lib/services/network/request.dart | 11 +++++++---- lib/services/network/request_helper.dart | 4 ++-- lib/services/storage/storage.dart | 3 +++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/services/network/request.dart b/lib/services/network/request.dart index 63d5035..13dd08c 100644 --- a/lib/services/network/request.dart +++ b/lib/services/network/request.dart @@ -35,6 +35,9 @@ class RequestService { if (body != null) _requestBody = body; } + String? get _generateBody => + _requestBody == null ? null : jsonEncode(_requestBody); + Future httpGet() async { try { final response = await http @@ -59,7 +62,7 @@ class RequestService { final response = await http .post( Uri.parse(url), - body: json.encode(_requestBody), + body: _generateBody, headers: _headers, ) .timeout( @@ -81,7 +84,7 @@ class RequestService { final response = await http .delete( Uri.parse(url), - body: json.encode(_requestBody), + body: _generateBody, headers: _headers, ) .timeout( @@ -130,7 +133,7 @@ class RequestService { final response = await http .put( Uri.parse(url), - body: json.encode(_requestBody), + body: _generateBody, headers: _headers, ) .timeout( @@ -151,7 +154,7 @@ class RequestService { _body = json.decode(response.body); } } - errorMessage = _errorMessageGenerator(response); + if (!isSuccess) errorMessage = _errorMessageGenerator(response); } bool _handleError(http.Response? response) { diff --git a/lib/services/network/request_helper.dart b/lib/services/network/request_helper.dart index fe10939..1764ee7 100644 --- a/lib/services/network/request_helper.dart +++ b/lib/services/network/request_helper.dart @@ -18,10 +18,10 @@ class RequestHelper { static String direct(int id) => _baseUserUrl + '/direct/$id'; - static String markRadar(int id) => _baseRadarUrl + '$id/mark'; + static String markRadar(int id) => _baseRadarUrl + '/$id/mark'; static String radarDetails(int id) => _baseRadarUrl + '/$id'; static String radarComments(int id) => _baseRadarUrl + '/$id/comments'; - static String markNews(int id) => _baseNewsUrl + '$id/mark'; + static String markNews(int id) => _baseNewsUrl + '/$id/mark'; static String newsDetails(int id) => _baseNewsUrl + '/$id'; static String newsComments(int id) => _baseNewsUrl + '/$id/comments'; static String radarOverviews({ diff --git a/lib/services/storage/storage.dart b/lib/services/storage/storage.dart index 7c398e6..a7d7684 100644 --- a/lib/services/storage/storage.dart +++ b/lib/services/storage/storage.dart @@ -1,4 +1,5 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:universal_html/html.dart'; class StorageService { static late String appDocsDir; @@ -20,4 +21,6 @@ class StorageService { static Future delete({required String key}) async { _storage.delete(key: key); } + + static Storage get webStorage => window.localStorage; }