Api 2.0 changes cont.

master-Api2.0
Sikander Saleem 9 months ago
parent db67242a20
commit ce81ee62c2

@ -16,15 +16,11 @@ class APIError {
int? errorCode;
int? errorType;
String? errorMessage;
int? errorStatusCode;
int? errorStatusCode;
APIError(this.errorCode, this.errorMessage, this.errorType, this.errorStatusCode);
Map<String, dynamic> toJson() => {
'errorCode': errorCode,
'errorMessage': errorMessage,
'errorType': errorType,
'ErrorStatusCode': errorStatusCode
};
Map<String, dynamic> toJson() => {'errorCode': errorCode, 'errorMessage': errorMessage, 'errorType': errorType, 'ErrorStatusCode': errorStatusCode};
@override
String toString() {
@ -46,7 +42,7 @@ APIException _throwAPIException(Response response) {
APIError? apiError;
if (response.body != null && response.body.isNotEmpty) {
var jsonError = jsonDecode(response.body);
apiError = APIError(jsonError['ErrorCode'], jsonError['ErrorMessage'], jsonError['ErrorType'],jsonError['ErrorStatusCode']);
apiError = APIError(jsonError['ErrorCode'], jsonError['ErrorMessage'], jsonError['ErrorType'], jsonError['ErrorStatusCode']);
}
return APIException(APIException.BAD_REQUEST, error: apiError);
case 401:
@ -73,7 +69,7 @@ class ApiClient {
factory ApiClient() => _instance;
Future<U> postJsonForObject<T, U>(FactoryConstructor<U> factoryConstructor, String url, T jsonObject,
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0, bool isFormData = false}) async {
{String? token, Map<String, dynamic>? queryParameters, Map<String, String>? headers, int retryTimes = 0, bool isFormData = false, bool returnJsonData = true}) async {
var _headers = {'Accept': 'application/json'};
if (headers != null && headers.isNotEmpty) {
_headers.addAll(headers);
@ -84,22 +80,22 @@ class ApiClient {
print("body:$bodyJson");
}
var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: _headers, retryTimes: retryTimes, isFormData: isFormData);
// try {
if (!kReleaseMode) {
logger.i("res: " + response.body);
}
// try {
if (!kReleaseMode) {
logger.i("res: " + response.body);
}
var jsonData = jsonDecode(response.body);
if (jsonData["IsAuthenticated"] != null) {
AppState().setIsAuthenticated = jsonData["IsAuthenticated"];
}
if (jsonData["ErrorMessage"] == null) {
return factoryConstructor(jsonData["Data"]);
} else {
APIError? apiError;
apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage'], jsonData['ErrorType'] ?? 0, jsonData['ErrorStatusCode']);
throw APIException(APIException.BAD_REQUEST, error: apiError);
}
var jsonData = jsonDecode(response.body);
if (jsonData["IsAuthenticated"] != null) {
AppState().setIsAuthenticated = jsonData["IsAuthenticated"];
}
if (jsonData["ErrorMessage"] == null) {
return factoryConstructor(returnJsonData ? jsonData["Data"] : jsonData);
} else {
APIError? apiError;
apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage'], jsonData['ErrorType'] ?? 0, jsonData['ErrorStatusCode']);
throw APIException(APIException.BAD_REQUEST, error: apiError);
}
// } catch (ex) {
// if (ex is APIException) {
// rethrow;
@ -147,7 +143,7 @@ class ApiClient {
}
var response = await _post(Uri.parse(url), body: requestBody, headers: _headers).timeout(Duration(seconds: 120));
if (response. statusCode >= 200 && response.statusCode < 300) {
if (response.statusCode >= 200 && response.statusCode < 300) {
return response;
} else {
throw _throwAPIException(response);

@ -55,7 +55,7 @@ class LoginApiClient {
String url = "${ApiConsts.authRest}CheckMobileAppVersion";
Map<String, dynamic> postParams = {};
postParams.addAll(AppState().postParamsJson);
return await ApiClient().postJsonForObject((json) => CheckMobileAppVersionModel.fromJson(json), url, postParams);
return await ApiClient().postJsonForObject((json) => CheckMobileAppVersionModel.fromJson(json), url, postParams,returnJsonData: false);
}
Future<MemberLoginListModel?> memberLogin(String username, String password) async {

@ -619,7 +619,7 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
int.tryParse(AppState().memberLoginList?.pMOBILENUMBER ?? ""),
(value, TextEditingController _pinPutController) async {
Utils.showLoading(context);
try {
//try {
GenericResponseModel? genericResponseModel = await LoginApiClient().checkActivationCode(true, AppState().memberLoginList?.pMOBILENUMBER, value, AppState().getUserName);
GenericResponseModel? genericResponseModel1 = await LoginApiClient().insertMobileLoginInfoNEW(
AppState().memberLoginList?.pEMAILADDRESS ?? "",
@ -648,22 +648,22 @@ class _VerifyLoginScreenState extends State<VerifyLoginScreen> {
Utils.hideLoading(context);
Navigator.pop(context);
Navigator.pushNamedAndRemoveUntil(context, AppRoutes.dashboard, (Route<dynamic> route) => false);
} catch (ex) {
print(ex);
_pinPutController.clear();
otpFieldClear.value = "";
Utils.hideLoading(context);
Utils.handleException(ex, context, null);
dynamic errorCode = ex;
if(errorCode.error.errorStatusCode ==699){
Future.delayed(const Duration(seconds: 2), ()
{
Navigator.pop(context);
Navigator.pushNamedAndRemoveUntil(
context, AppRoutes.login, (Route<dynamic> route) => false);
});
}
}
// } catch (ex) {
// print(ex);
// _pinPutController.clear();
// otpFieldClear.value = "";
// Utils.hideLoading(context);
// Utils.handleException(ex, context, null);
// dynamic errorCode = ex;
// if(errorCode.error.errorStatusCode ==699){
// Future.delayed(const Duration(seconds: 2), ()
// {
// Navigator.pop(context);
// Navigator.pushNamedAndRemoveUntil(
// context, AppRoutes.login, (Route<dynamic> route) => false);
// });
// }
// }
},
() => {
Navigator.pop(context),

Loading…
Cancel
Save