|
|
|
@ -264,6 +264,7 @@ import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:http/http.dart';
|
|
|
|
import 'package:http/http.dart';
|
|
|
|
import 'package:http/io_client.dart';
|
|
|
|
import 'package:http/io_client.dart';
|
|
|
|
|
|
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
|
|
import 'package:mohem_flutter_app/exceptions/api_exception.dart';
|
|
|
|
import 'package:mohem_flutter_app/exceptions/api_exception.dart';
|
|
|
|
import 'package:mohem_flutter_app/main.dart';
|
|
|
|
import 'package:mohem_flutter_app/main.dart';
|
|
|
|
import 'package:mohem_flutter_app/models/generic_mapper_model.dart';
|
|
|
|
import 'package:mohem_flutter_app/models/generic_mapper_model.dart';
|
|
|
|
@ -379,7 +380,7 @@ class APIError {
|
|
|
|
|
|
|
|
|
|
|
|
class ApiResponse<T> {
|
|
|
|
class ApiResponse<T> {
|
|
|
|
final dynamic totalItemsCount;
|
|
|
|
final dynamic totalItemsCount;
|
|
|
|
final T data;
|
|
|
|
final T? data;
|
|
|
|
final dynamic messageStatus;
|
|
|
|
final dynamic messageStatus;
|
|
|
|
final dynamic errorMessage;
|
|
|
|
final dynamic errorMessage;
|
|
|
|
final dynamic errorEndUserMessage;
|
|
|
|
final dynamic errorEndUserMessage;
|
|
|
|
@ -474,6 +475,16 @@ class ApiClient {
|
|
|
|
printLongLog("body:$bodyJson");
|
|
|
|
printLongLog("body:$bodyJson");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!_headers.containsKey('Authorization') && jsonObject is Map && jsonObject.containsKey('tokenID') && AppState().isLogged) {
|
|
|
|
|
|
|
|
_headers['Authorization'] = 'Bearer ${jsonObject['tokenID']}';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove "logInTokenID" and "tokenID" from jsonObject if present
|
|
|
|
|
|
|
|
if (jsonObject is Map && AppState().isLogged) {
|
|
|
|
|
|
|
|
jsonObject.remove("logInTokenID");
|
|
|
|
|
|
|
|
jsonObject.remove("tokenID");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: _headers, retryTimes: retryTimes, isFormData: isFormData);
|
|
|
|
var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: _headers, retryTimes: retryTimes, isFormData: isFormData);
|
|
|
|
|
|
|
|
|
|
|
|
if (!kReleaseMode) {
|
|
|
|
if (!kReleaseMode) {
|
|
|
|
@ -485,7 +496,7 @@ class ApiClient {
|
|
|
|
// Handle authentication flag if present
|
|
|
|
// Handle authentication flag if present
|
|
|
|
if (jsonData["IsAuthenticated"] != null) {
|
|
|
|
if (jsonData["IsAuthenticated"] != null) {
|
|
|
|
print("IsAuthenticated Need to be upated: ${jsonData["IsAuthenticated"]}");
|
|
|
|
print("IsAuthenticated Need to be upated: ${jsonData["IsAuthenticated"]}");
|
|
|
|
// AppState().setIsAuthenticated = jsonData["IsAuthenticated"];
|
|
|
|
// // AppState().setIsAuthenticated = jsonData["IsAuthenticated"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create ApiResponse from the json
|
|
|
|
// Create ApiResponse from the json
|
|
|
|
@ -495,7 +506,6 @@ class ApiClient {
|
|
|
|
return factoryConstructor(jsonData);
|
|
|
|
return factoryConstructor(jsonData);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (apiResponse.messageStatus == null || apiResponse.messageStatus != 1) {
|
|
|
|
if (apiResponse.messageStatus == null || apiResponse.messageStatus != 1) {
|
|
|
|
|
|
|
|
|
|
|
|
logger.i(apiResponse.errorMessage);
|
|
|
|
logger.i(apiResponse.errorMessage);
|
|
|
|
throw APIException(
|
|
|
|
throw APIException(
|
|
|
|
APIException.OTHER,
|
|
|
|
APIException.OTHER,
|
|
|
|
@ -574,7 +584,6 @@ class ApiClient {
|
|
|
|
url = url + '?' + queryString;
|
|
|
|
url = url + '?' + queryString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var response = await _post(
|
|
|
|
var response = await _post(
|
|
|
|
Uri.parse(url),
|
|
|
|
Uri.parse(url),
|
|
|
|
body: requestBody,
|
|
|
|
body: requestBody,
|
|
|
|
|