http client class safeApiCall error state handle
This commit is contained in:
parent
5889717efe
commit
cd83375b98
|
|
@ -8,7 +8,7 @@
|
|||
<application
|
||||
android:name="${applicationName}"
|
||||
android:icon="@mipmap/launcher_icon"
|
||||
android:label="FTC">
|
||||
android:label="FTC Patient">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>Ftc Mobile App</string>
|
||||
<string>FTC Patient</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
|
|
|
|||
|
|
@ -10,13 +10,13 @@ class SplashScreenController extends GetxController {
|
|||
@override
|
||||
void onInit() {
|
||||
5.seconds.delay(() {
|
||||
// _gotoLoginScreen();
|
||||
_gotoLoginScreen();
|
||||
|
||||
if (_loginTokenNotFound) {
|
||||
_gotoLoginScreen();
|
||||
} else {
|
||||
_checkOngoingShift();
|
||||
}
|
||||
// if (_loginTokenNotFound) {
|
||||
// _gotoLoginScreen();
|
||||
// } else {
|
||||
// _checkOngoingShift();
|
||||
// }
|
||||
|
||||
});
|
||||
super.onInit();
|
||||
|
|
|
|||
|
|
@ -36,10 +36,10 @@ class _CustomDrawerState extends State<CustomDrawer> {
|
|||
Center(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
drawerController.selectedIndex.value = -1;
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamed(
|
||||
context, CustomRouteNames.kViewProfileScreenRoute);
|
||||
// drawerController.selectedIndex.value = -1;
|
||||
// Navigator.pop(context);
|
||||
// Navigator.pushNamed(
|
||||
// context, CustomRouteNames.kViewProfileScreenRoute);
|
||||
},
|
||||
child: Obx(() {
|
||||
return MyCircleImage(
|
||||
|
|
|
|||
|
|
@ -1,3 +1,7 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:ftc_mobile_app/utilities/enums/api_method.dart';
|
||||
|
||||
import '../ftc_mobile_app.dart';
|
||||
|
||||
class AuthService {
|
||||
|
|
@ -20,27 +24,43 @@ class AuthService {
|
|||
Map<String, dynamic> requestBody = {
|
||||
"email": email,
|
||||
"password": password,
|
||||
"role": "serviceuser", //role key h - user , serviceuser, staffmember, superadmin
|
||||
"fcm_tokens": {
|
||||
"token":
|
||||
"fY6_DGfGQ06OW4BUVEsEwG:APA91bGUFza2uhaaR0miN2jtY0ut7RuA5ObleZvqv2X8KLOBgksmDmgc9sHDdea-DBvHmz1aUwX1uhkysk92x50WQCLHPDD1VwGX5ybKhUwVdq4aBfI24vhXqMB-FksWXEZwzDAi9BA_",
|
||||
// "token": "${await FirebaseMessaging.instance.getToken()}",
|
||||
"deviceType": "android"
|
||||
"deviceType": Platform.isAndroid ? "android" : "ios",
|
||||
}
|
||||
};
|
||||
|
||||
ResponseModel responseModel = await _httpClient.customRequest(
|
||||
"POST",
|
||||
// ResponseModel responseModel = await _httpClient.customRequest(
|
||||
// "POST",
|
||||
// url: WebUrls.signInUrl,
|
||||
// requestBody: requestBody,
|
||||
// requestHeader: {'Content-Type': 'application/json'},
|
||||
// );
|
||||
|
||||
ResponseModel responseModel = await _httpClient.safeApiCall(
|
||||
method: ApiMethod.post,
|
||||
url: WebUrls.signInUrl,
|
||||
requestBody: requestBody,
|
||||
requestHeader: {'Content-Type': 'application/json'},
|
||||
body: requestBody,
|
||||
);
|
||||
if (responseModel.statusCode >= 200 && responseModel.statusCode <= 230) {
|
||||
|
||||
if ((responseModel.statusCode ~/ 100) == 2) {
|
||||
return true;
|
||||
} else {
|
||||
return {
|
||||
"message": responseModel.statusDescription,
|
||||
};
|
||||
}
|
||||
|
||||
// if (responseModel.statusCode >= 200 && responseModel.statusCode <= 230) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return {
|
||||
// "message": responseModel.statusDescription,
|
||||
// };
|
||||
// }
|
||||
}
|
||||
|
||||
//verify Otp and if success storing token and user data
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import 'dart:async';
|
|||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:ftc_mobile_app/utilities/enums/api_method.dart';
|
||||
|
|
@ -86,6 +85,21 @@ class HttpRequestClient {
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
Future<Map<String, String>> getRequestHeader({
|
||||
bool isBearer = true,
|
||||
bool isContentType = true,
|
||||
}) async {
|
||||
String token = LocalStorageManager.getLoginToken();
|
||||
// //todo remove this in end
|
||||
// String token =
|
||||
// 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhIjp0cnVlLCJuIjoiSmFtc2hhaWQgU2FiaXIiLCJlIjoiamFtc2hhaWRzYWJpcjQxMTk4MEBnbWFpbC5jb20iLCJkIjoiNjQ2NTEyN2E3MmJjNzEzY2E4NDYwY2IzIiwicCI6Ii91cGxvYWRzL2RwL2RlZmF1bHQucG5nIiwiciI6Il9hIiwiaWF0IjoxNjkzMjIzNTIzfQ.EtpS_o0kEhdlNzCyFdFNNQzHd0IipTw8BEuUBVgfYok';
|
||||
Map<String, String> header = {
|
||||
'Authorization': isBearer ? 'Bearer $token' : token,
|
||||
if (isContentType) 'Content-Type': 'application/json'
|
||||
};
|
||||
return header;
|
||||
}
|
||||
|
||||
Future<ResponseModel> getRequestWithOutHeader({required String url}) async {
|
||||
try {
|
||||
http.Response response = await http
|
||||
|
|
@ -582,23 +596,6 @@ class HttpRequestClient {
|
|||
}
|
||||
}
|
||||
|
||||
Future<Map<String, String>> getRequestHeader({
|
||||
bool isBearer = true,
|
||||
bool isContentType = true,
|
||||
}) async {
|
||||
// String token = SessionManagement().getSessionToken(
|
||||
// tokenKey: SessionKeys.kUserTokenKey,
|
||||
// );
|
||||
//todo remove this in end
|
||||
String token =
|
||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhIjp0cnVlLCJuIjoiSmFtc2hhaWQgU2FiaXIiLCJlIjoiamFtc2hhaWRzYWJpcjQxMTk4MEBnbWFpbC5jb20iLCJkIjoiNjQ2NTEyN2E3MmJjNzEzY2E4NDYwY2IzIiwicCI6Ii91cGxvYWRzL2RwL2RlZmF1bHQucG5nIiwiciI6Il9hIiwiaWF0IjoxNjkzMjIzNTIzfQ.EtpS_o0kEhdlNzCyFdFNNQzHd0IipTw8BEuUBVgfYok';
|
||||
Map<String, String> header = {
|
||||
'Authorization': isBearer ? 'Bearer $token' : token,
|
||||
if (isContentType) 'Content-Type': 'application/json'
|
||||
};
|
||||
return header;
|
||||
}
|
||||
|
||||
Future<dynamic> safeApiCall({
|
||||
required ApiMethod method,
|
||||
required String url,
|
||||
|
|
@ -615,7 +612,7 @@ class HttpRequestClient {
|
|||
// }
|
||||
|
||||
Map<String, String> customHeader = await getRequestHeader();
|
||||
if(headers != null) customHeader.addAll(headers!);
|
||||
if (headers != null) customHeader.addAll(headers);
|
||||
|
||||
final dio = Dio()
|
||||
..interceptors.add(Logging())
|
||||
|
|
@ -660,9 +657,18 @@ class HttpRequestClient {
|
|||
break;
|
||||
}
|
||||
|
||||
return ResponseModel.fromJson(jsonDecode(response.toString()))
|
||||
..statusCode = response.statusCode ?? 0;
|
||||
final Map<String, dynamic> map = jsonDecode(response.toString());
|
||||
final statusFail = (map['status'] is String &&
|
||||
(map['status'] as String).toLowerCase() == "fail");
|
||||
final status400 = (map['status'] is int && map['status'] == 400);
|
||||
if (map.containsKey('status') && (statusFail || status400)) {
|
||||
return ResponseModel.named(
|
||||
statusCode: 0,
|
||||
statusDescription: map['message'],
|
||||
);
|
||||
}
|
||||
|
||||
return ResponseModel.fromJson(map)..statusCode = response.statusCode ?? 0;
|
||||
} on DioException catch (e) {
|
||||
return ResponseModel.named(
|
||||
statusCode: e.response?.statusCode ?? 0,
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class RotaService {
|
|||
Map<String, dynamic> requestBody = {
|
||||
"startDate": startDateMills,
|
||||
"endDate": endDateMills,
|
||||
"staffUserId": LocalStorageManager.userId,
|
||||
"serviceUserId": LocalStorageManager.userId,
|
||||
// "startDate": 1720983600000,
|
||||
// "endDate": 1721502000000,
|
||||
// "staffUserId": "659653a31faf0d9fa4e15d5d",
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class WebUrls extends _BaseUrl {
|
|||
|
||||
static String socketUrl = 'http://16.171.242.62:3000';
|
||||
|
||||
static String signInUrl = "$baseUrl/users/signin";
|
||||
static String signInUrl = "$baseUrl/users/signInApp";
|
||||
static String passwordLessSignInUrl = "$baseUrl/users/passwordLessLogin";
|
||||
static String forgetPasswordUrl = "$baseUrl/users/forgot-password";
|
||||
static String verifyCodeUrl = "$baseUrl/users/verify-code";
|
||||
|
|
@ -77,7 +77,7 @@ class WebUrls extends _BaseUrl {
|
|||
"$baseUrl/staffWorkLoads/getStaffWorkLoadsWithFullDetails";
|
||||
static String requestHoliday =
|
||||
"$baseUrl/staffHolidayRequests/createStaffHolidayRequest";
|
||||
static String myShifts = "$baseUrl/liveRoster/checkExistShiftByStaffId";
|
||||
static String myShifts = "$baseUrl/liveRoster/checkExistShiftByServiceUserid";
|
||||
static String unassignedShifts = "$baseUrl/liveRoster/unassignedShifts";
|
||||
static String assignStaffToShift = "$baseUrl/liveRoster/assignStaffToShift";
|
||||
|
||||
|
|
|
|||
Reference in New Issue