mark attendance session expire fixed

merge-requests/140/head
Sikander Saleem 2 years ago
parent f4b57a33f9
commit e10ea6b023

@ -19,7 +19,11 @@ class APIError {
APIError(this.errorCode, this.errorMessage, this.errorType);
Map<String, dynamic> toJson() => {'errorCode': errorCode, 'errorMessage': errorMessage, 'errorType': errorType,};
Map<String, dynamic> toJson() => {
'errorCode': errorCode,
'errorMessage': errorMessage,
'errorType': errorType,
};
@override
String toString() {
@ -79,28 +83,34 @@ 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);
}
var jsonData = jsonDecode(response.body);
if (jsonData["IsAuthenticated"] != null) {
AppState().setIsAuthenticated = jsonData["IsAuthenticated"];
}
if (jsonData["ErrorMessage"] == null) {
return factoryConstructor(jsonData);
} else {
APIError? apiError;
apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage'], jsonData['ErrorType']);
throw APIException(APIException.BAD_REQUEST, error: apiError);
try {
if (!kReleaseMode) {
logger.i("res: " + response.body);
}
var jsonData = jsonDecode(response.body);
if (jsonData["MessageStatus"] == 2) {
AppState().setIsAuthenticated = false;
}
// else if (jsonData["ErrorEndUserMessage"] != null && jsonData["ErrorEndUserMessage"].toString().contains("MBL-APP-375")) {
// print("Custom:${jsonData["ErrorEndUserMessage"]}");
// AppState().setIsAuthenticated = false;
// }
if (jsonData["ErrorMessage"] == null && jsonData["MessageStatus"] == 1) {
return factoryConstructor(jsonData);
} else {
APIError? apiError;
apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage'], jsonData['ErrorType'] ?? 0);
throw APIException(APIException.BAD_REQUEST, error: apiError);
}
} catch (ex) {
if (ex is APIException) {
rethrow;
} else {
throw APIException(APIException.BAD_RESPONSE_FORMAT, arguments: ex);
}
}
// } catch (ex) {
// if (ex is APIException) {
// rethrow;
// } else {
// throw APIException(APIException.BAD_RESPONSE_FORMAT, arguments: ex);
// }
// }
}
Future<Response> postJsonForResponse<T>(String url, T jsonObject,

@ -70,7 +70,7 @@ class AppState {
bool get getIsDemoMarathon => _isDemoMarathon;
final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 31, versionID: 3.8, mobileType: Platform.isAndroid ? "android" : "ios");
final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 31, versionID: 3.9, mobileType: Platform.isAndroid ? "android" : "ios");
void setPostParamsInitConfig() {
isAuthenticated = false;

@ -3,8 +3,8 @@ import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart';
class ApiConsts {
//static String baseUrl = "http://10.200.204.20:2801/"; // Local server
// static String baseUrl = "https://erptstapp.srca.org.sa"; // SRCA server
static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server
// static String baseUrl = "https://hmgwebservices.com"; // Live server
// static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server
static String baseUrl = "https://hmgwebservices.com"; // Live server
static String baseUrlServices = baseUrl + "/Services/"; // server
// static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server
static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/";

@ -50,23 +50,23 @@ class _TodayAttendanceScreenState extends State<TodayAttendanceScreen2> {
icon: const Icon(Icons.arrow_back_ios, color: Colors.white),
onPressed: () => Navigator.pop(context),
),
actions: [
IconButton(
onPressed: () {
data.fetchAttendanceTracking(context);
},
icon: const Icon(
Icons.ac_unit,
color: Colors.white,
),
)
],
// actions: [
// IconButton(
// onPressed: () {
// data.fetchAttendanceTracking(context);
// },
// icon: const Icon(
// Icons.ac_unit,
// color: Colors.white,
// ),
// )
// ],
),
backgroundColor: MyColors.backgroundBlackColor,
body: Consumer<DashboardProviderModel>(
builder: (context, model, child) {
return (model.isAttendanceTrackingLoading
? Center(child: CircularProgressIndicator())
? const Center(child: CircularProgressIndicator())
: Column(
children: [
Container(

@ -226,13 +226,13 @@ class _LoginScreenState extends State<LoginScreen> {
}),
),
20.height,
DefaultButton(
"Connect HMG Network",
() async {
SystemChannels.textInput.invokeMethod('TextInput.hide');
connectWithHmgNetwork();
},
),
// DefaultButton(
// "Connect HMG Network",
// () async {
// SystemChannels.textInput.invokeMethod('TextInput.hide');
// connectWithHmgNetwork();
// },
// ),
],
),
)

@ -12,6 +12,7 @@ import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/models/generic_response_model.dart';
import 'package:mohem_flutter_app/models/privilege_list_model.dart';
import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart';
import 'package:mohem_flutter_app/ui/dialogs/success_dialog.dart';
import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.dart';
@ -47,7 +48,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
void checkAttendanceAvailability() async {
bool isAvailable = await NfcManager.instance.isAvailable();
setState(() {
AppState().privilegeListModel!.forEach((element) {
AppState().privilegeListModel!.forEach((PrivilegeListModel element) {
if (element.serviceName == "enableNFC") {
if (isAvailable) if (element.previlege ?? false) isNfcEnabled = true;
} else if (element.serviceName == "enableQR") {
@ -144,6 +145,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
Future<void> performNfcAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async {
if (Platform.isIOS) {
Utils.readNFc(onRead: (String nfcId) async {
Utils.showLoading(context);
try {
@ -152,7 +154,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
Utils.hideLoading(context);
showDialog(
context: context,
builder: (cxt) => ConfirmDialog(
builder: (BuildContext cxt) => ConfirmDialog(
message: g?.errorEndUserMessage ?? "Unexpected error occurred",
onTap: () {
Navigator.pop(context);
@ -172,9 +174,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
}
} catch (ex) {
Utils.hideLoading(context);
Utils.handleException(ex, context, (msg) {
Utils.confirmDialog(context, msg);
});
Utils.handleException(ex, context, null);
}
});
} else {
@ -186,7 +186,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
Utils.hideLoading(context);
showDialog(
context: context,
builder: (cxt) => ConfirmDialog(
builder: (BuildContext cxt) => ConfirmDialog(
message: g?.errorEndUserMessage ?? "Unexpected error occurred",
onTap: () {
Navigator.pop(context);
@ -206,7 +206,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
} catch (ex) {
print(ex);
Utils.hideLoading(context);
Utils.handleException(ex, context, (msg) {
Utils.handleException(ex, context, (String msg) {
Utils.confirmDialog(context, msg);
});
}
@ -219,19 +219,23 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
bool isConnected = await WiFiForIoTPlugin.connect(AppState().getMohemmWifiSSID ?? "",
password: AppState().getMohemmWifiPassword ?? "", joinOnce: Platform.isIOS ? false : true, security: NetworkSecurity.WPA, withInternet: false);
if (isConnected) {
if (Platform.isIOS) {
await closeWifiRequest();
await Future.delayed(Duration(seconds: 6));
} else {
await WiFiForIoTPlugin.forceWifiUsage(true);
}
// if (Platform.isIOS) {
// await closeWifiRequest();
// await Future.delayed(Duration(seconds: 6));
// } else {
// await WiFiForIoTPlugin.forceWifiUsage(true);
// }
await WiFiForIoTPlugin.forceWifiUsage(true);
await Future.delayed(const Duration(seconds: 6));
try {
GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 3, nfcValue: "", isGpsRequired: isWifiLocationEnabled, lat: lat, long: lng);
bool status = await model.fetchAttendanceTracking(context);
Utils.hideLoading(context);
if (Platform.isAndroid) {
await closeWifiRequest();
}
// if (Platform.isAndroid) {
// await closeWifiRequest();
// }
await closeWifiRequest();
showMDialog(
context,
backgroundColor: Colors.transparent,
@ -241,9 +245,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
} catch (ex) {
await closeWifiRequest();
Utils.hideLoading(context);
Utils.handleException(ex, context, (msg) {
Utils.confirmDialog(context, msg);
});
Utils.handleException(ex, context, null);
}
} else {
Utils.hideLoading(context);
@ -261,7 +263,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
Future<void> performQrCodeAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async {
var qrCodeValue = await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => QrScannerDialog(),
builder: (BuildContext context) => QrScannerDialog(),
),
);
if (qrCodeValue != null) {
@ -279,9 +281,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
} catch (ex) {
print(ex);
Utils.hideLoading(context);
Utils.handleException(ex, context, (msg) {
Utils.confirmDialog(context, msg);
});
Utils.handleException(ex, context, null);
}
}
}
@ -295,9 +295,7 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
} catch (ex) {
print(ex);
Utils.hideLoading(context);
Utils.handleException(ex, context, (msg) {
Utils.confirmDialog(context, msg);
});
Utils.handleException(ex, context, null);
}
}

Loading…
Cancel
Save