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