|
|
|
@ -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;
|
|
|
|
@ -391,7 +392,7 @@ class ApiResponse<T> {
|
|
|
|
String toRawJson() => json.encode(toJson());
|
|
|
|
String toRawJson() => json.encode(toJson());
|
|
|
|
|
|
|
|
|
|
|
|
factory ApiResponse.fromJson(Map<String, dynamic> json) => ApiResponse(
|
|
|
|
factory ApiResponse.fromJson(Map<String, dynamic> json) => ApiResponse(
|
|
|
|
totalItemsCount: json["TotalItemsCount"] ?? json["totalItemsCount"] ,
|
|
|
|
totalItemsCount: json["TotalItemsCount"] ?? json["totalItemsCount"],
|
|
|
|
data: json["Data"] ?? json["data"],
|
|
|
|
data: json["Data"] ?? json["data"],
|
|
|
|
messageStatus: json["MessageStatus"] ?? json["messageStatus"],
|
|
|
|
messageStatus: json["MessageStatus"] ?? json["messageStatus"],
|
|
|
|
errorMessage: json["ErrorMessage"] ?? json["errorMessage"],
|
|
|
|
errorMessage: json["ErrorMessage"] ?? json["errorMessage"],
|
|
|
|
@ -406,7 +407,7 @@ class ApiResponse<T> {
|
|
|
|
"ErrorEndUserMessage": errorEndUserMessage,
|
|
|
|
"ErrorEndUserMessage": errorEndUserMessage,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool get isSuccess => messageStatus == 1 && (errorMessage==null || errorMessage!.isEmpty );
|
|
|
|
bool get isSuccess => messageStatus == 1 && (errorMessage == null || errorMessage!.isEmpty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
APIException _throwAPIException(Response response) {
|
|
|
|
APIException _throwAPIException(Response response) {
|
|
|
|
@ -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
|
|
|
|
@ -494,8 +505,7 @@ class ApiClient {
|
|
|
|
if (apiResponse.isSuccess) {
|
|
|
|
if (apiResponse.isSuccess) {
|
|
|
|
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,
|
|
|
|
@ -506,7 +516,7 @@ class ApiClient {
|
|
|
|
response.statusCode,
|
|
|
|
response.statusCode,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}else {
|
|
|
|
} else {
|
|
|
|
throw APIException(
|
|
|
|
throw APIException(
|
|
|
|
APIException.BAD_REQUEST,
|
|
|
|
APIException.BAD_REQUEST,
|
|
|
|
error: APIError(
|
|
|
|
error: APIError(
|
|
|
|
@ -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,
|
|
|
|
|