D1APP-22 service updates

This commit is contained in:
MohammadTaha Basiri 2022-01-18 18:17:23 +03:30
parent 61aea52161
commit b044c34231
3 changed files with 12 additions and 6 deletions

View File

@ -35,6 +35,9 @@ class RequestService {
if (body != null) _requestBody = body; if (body != null) _requestBody = body;
} }
String? get _generateBody =>
_requestBody == null ? null : jsonEncode(_requestBody);
Future<void> httpGet() async { Future<void> httpGet() async {
try { try {
final response = await http final response = await http
@ -59,7 +62,7 @@ class RequestService {
final response = await http final response = await http
.post( .post(
Uri.parse(url), Uri.parse(url),
body: json.encode(_requestBody), body: _generateBody,
headers: _headers, headers: _headers,
) )
.timeout( .timeout(
@ -81,7 +84,7 @@ class RequestService {
final response = await http final response = await http
.delete( .delete(
Uri.parse(url), Uri.parse(url),
body: json.encode(_requestBody), body: _generateBody,
headers: _headers, headers: _headers,
) )
.timeout( .timeout(
@ -130,7 +133,7 @@ class RequestService {
final response = await http final response = await http
.put( .put(
Uri.parse(url), Uri.parse(url),
body: json.encode(_requestBody), body: _generateBody,
headers: _headers, headers: _headers,
) )
.timeout( .timeout(
@ -151,7 +154,7 @@ class RequestService {
_body = json.decode(response.body); _body = json.decode(response.body);
} }
} }
errorMessage = _errorMessageGenerator(response); if (!isSuccess) errorMessage = _errorMessageGenerator(response);
} }
bool _handleError(http.Response? response) { bool _handleError(http.Response? response) {

View File

@ -18,10 +18,10 @@ class RequestHelper {
static String direct(int id) => _baseUserUrl + '/direct/$id'; 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 radarDetails(int id) => _baseRadarUrl + '/$id';
static String radarComments(int id) => _baseRadarUrl + '/$id/comments'; 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 newsDetails(int id) => _baseNewsUrl + '/$id';
static String newsComments(int id) => _baseNewsUrl + '/$id/comments'; static String newsComments(int id) => _baseNewsUrl + '/$id/comments';
static String radarOverviews({ static String radarOverviews({

View File

@ -1,4 +1,5 @@
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:universal_html/html.dart';
class StorageService { class StorageService {
static late String appDocsDir; static late String appDocsDir;
@ -20,4 +21,6 @@ class StorageService {
static Future<void> delete({required String key}) async { static Future<void> delete({required String key}) async {
_storage.delete(key: key); _storage.delete(key: key);
} }
static Storage get webStorage => window.localStorage;
} }