From 3327130e74d4e64624975d2333c04792fde5042f Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Thu, 27 Jun 2024 17:04:40 +0300 Subject: [PATCH] Attendance location updates --- lib/app_state/app_state.dart | 2 +- lib/widgets/location/Location.dart | 4 +++- lib/widgets/mark_attendance_widget.dart | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/app_state/app_state.dart b/lib/app_state/app_state.dart index 2e8e2ad..cc11126 100644 --- a/lib/app_state/app_state.dart +++ b/lib/app_state/app_state.dart @@ -90,7 +90,7 @@ class AppState { String get getHuaweiPushToken => _huaweiPushToken; - final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 31, versionID: 6.0, mobileType: Platform.isAndroid ? "android" : "ios"); + final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 31, versionID: 8.0, mobileType: Platform.isAndroid ? "android" : "ios"); void setPostParamsInitConfig() { isAuthenticated = false; diff --git a/lib/widgets/location/Location.dart b/lib/widgets/location/Location.dart index 67d3cdd..47babca 100644 --- a/lib/widgets/location/Location.dart +++ b/lib/widgets/location/Location.dart @@ -35,7 +35,7 @@ class Location { }); } - static void getCurrentLocation(Function(Position position, bool isMocked) callback, BuildContext context) { + static void getCurrentLocation(Function(Position position, bool isMocked) callback, Function errorCallBack, BuildContext context) { void done(Position position) { //AppStorage.sp.saveLocation(position); bool isMocked = position.isMocked; @@ -46,6 +46,8 @@ class Location { if (granted) { Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: const Duration(seconds: 5)).then((value) { done(value); + }).catchError((err) { + errorCallBack(); }); } else { // AppPermissions diff --git a/lib/widgets/mark_attendance_widget.dart b/lib/widgets/mark_attendance_widget.dart index 75a5ef5..508ed00 100644 --- a/lib/widgets/mark_attendance_widget.dart +++ b/lib/widgets/mark_attendance_widget.dart @@ -171,14 +171,21 @@ class _MarkAttendanceWidgetState extends State { if (isEnabled) { location.Location.havePermission((bool permission) { if (permission) { + Utils.showLoading(context); location.Location.getCurrentLocation( (Position position, bool isMocked) { if (isMocked) { + Utils.hideLoading(context); markFakeAttendance("NFC", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); } else { + Utils.hideLoading(context); performNfcAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? ""); } }, + () { + Utils.hideLoading(context); + Utils.confirmDialog(context, "Unable to determine your location, Please make sure that your location services are turned on & working."); + }, context, ); } else { @@ -218,14 +225,21 @@ class _MarkAttendanceWidgetState extends State { if (isEnabled) { location.Location.havePermission((bool permission) { if (permission) { + Utils.showLoading(context); location.Location.getCurrentLocation( (Position position, bool isMocked) { if (isMocked) { + Utils.hideLoading(context); markFakeAttendance("WIFI", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); } else { + Utils.hideLoading(context); performWifiAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? ""); } }, + () { + Utils.hideLoading(context); + Utils.confirmDialog(context, "Unable to determine your location, Please make sure that your location services are turned on & working."); + }, context, ); } else { @@ -265,14 +279,21 @@ class _MarkAttendanceWidgetState extends State { if (isEnabled) { location.Location.havePermission((bool permission) { if (permission) { + Utils.showLoading(context); location.Location.getCurrentLocation( (Position position, bool isMocked) { if (isMocked) { + Utils.hideLoading(context); markFakeAttendance("QR", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); } else { + Utils.hideLoading(context); performQrCodeAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? ""); } }, + () { + Utils.hideLoading(context); + Utils.confirmDialog(context, "Unable to determine your location, Please make sure that your location services are turned on & working."); + }, context, ); } else {