Api 2.0 changes cont.

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

@ -17,14 +17,10 @@ class APIError {
int? errorType; int? errorType;
String? errorMessage; String? errorMessage;
int? errorStatusCode; int? errorStatusCode;
APIError(this.errorCode, this.errorMessage, this.errorType, this.errorStatusCode); APIError(this.errorCode, this.errorMessage, this.errorType, this.errorStatusCode);
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {'errorCode': errorCode, 'errorMessage': errorMessage, 'errorType': errorType, 'ErrorStatusCode': errorStatusCode};
'errorCode': errorCode,
'errorMessage': errorMessage,
'errorType': errorType,
'ErrorStatusCode': errorStatusCode
};
@override @override
String toString() { String toString() {
@ -46,7 +42,7 @@ APIException _throwAPIException(Response response) {
APIError? apiError; APIError? apiError;
if (response.body != null && response.body.isNotEmpty) { if (response.body != null && response.body.isNotEmpty) {
var jsonError = jsonDecode(response.body); 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); return APIException(APIException.BAD_REQUEST, error: apiError);
case 401: case 401:
@ -73,7 +69,7 @@ class ApiClient {
factory ApiClient() => _instance; factory ApiClient() => _instance;
Future<U> postJsonForObject<T, U>(FactoryConstructor<U> factoryConstructor, String url, T jsonObject, 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'}; var _headers = {'Accept': 'application/json'};
if (headers != null && headers.isNotEmpty) { if (headers != null && headers.isNotEmpty) {
_headers.addAll(headers); _headers.addAll(headers);
@ -94,7 +90,7 @@ class ApiClient {
AppState().setIsAuthenticated = jsonData["IsAuthenticated"]; AppState().setIsAuthenticated = jsonData["IsAuthenticated"];
} }
if (jsonData["ErrorMessage"] == null) { if (jsonData["ErrorMessage"] == null) {
return factoryConstructor(jsonData["Data"]); return factoryConstructor(returnJsonData ? jsonData["Data"] : jsonData);
} else { } else {
APIError? apiError; APIError? apiError;
apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage'], jsonData['ErrorType'] ?? 0, jsonData['ErrorStatusCode']); apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage'], jsonData['ErrorType'] ?? 0, jsonData['ErrorStatusCode']);
@ -147,7 +143,7 @@ class ApiClient {
} }
var response = await _post(Uri.parse(url), body: requestBody, headers: _headers).timeout(Duration(seconds: 120)); 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; return response;
} else { } else {
throw _throwAPIException(response); throw _throwAPIException(response);

@ -55,7 +55,7 @@ class LoginApiClient {
String url = "${ApiConsts.authRest}CheckMobileAppVersion"; String url = "${ApiConsts.authRest}CheckMobileAppVersion";
Map<String, dynamic> postParams = {}; Map<String, dynamic> postParams = {};
postParams.addAll(AppState().postParamsJson); 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 { Future<MemberLoginListModel?> memberLogin(String username, String password) async {

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

Loading…
Cancel
Save