From ac82706eaaa57da843ca1de530c7c090eef3658d Mon Sep 17 00:00:00 2001 From: "taha.alam" Date: Sun, 13 Oct 2024 17:13:29 +0300 Subject: [PATCH] location checkin added. --- lib/widgets/mark_attendance_widget.dart | 93 ++++++++++++++++++++++++- pubspec.yaml | 2 +- 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/lib/widgets/mark_attendance_widget.dart b/lib/widgets/mark_attendance_widget.dart index 508ed00..cc829dd 100644 --- a/lib/widgets/mark_attendance_widget.dart +++ b/lib/widgets/mark_attendance_widget.dart @@ -157,7 +157,7 @@ class _MarkAttendanceWidgetState extends State { LocaleKeys.markAttendance.tr().toSectionHeading(), LocaleKeys.selectMethodOfAttendance.tr().toText11(color: const Color(0xff535353)), GridView( - physics: const NeverScrollableScrollPhysics(), + physics: const BouncingScrollPhysics(), shrinkWrap: true, padding: const EdgeInsets.only(bottom: 0, top: 21), gridDelegate: @@ -324,6 +324,59 @@ class _MarkAttendanceWidgetState extends State { }); } }), + attendanceMethod("Location" ,"assets/images/ic_qr.svg", true, () async { + if (AppState().getIsHuawei) { + checkHuaweiLocationPermission("location"); + } else { + location.Location.isEnabled((bool isEnabled) { + 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("location", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); + } else { + Utils.hideLoading(context); + performLocationAttendance(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 { + showDialog( + context: context, + builder: (BuildContext cxt) => ConfirmDialog( + message: "You need to give location permission to mark attendance", + onTap: () async { + Navigator.pop(context); + await Geolocator.openAppSettings(); + }, + ), + ); + } + }); + } else { + showDialog( + context: context, + builder: (BuildContext cxt) => ConfirmDialog( + message: "You need to enable location services to mark attendance", + onTap: () async { + Navigator.pop(context); + await Geolocator.openLocationSettings(); + }, + ), + ); + } + }); + } + }), ], ) ], @@ -357,6 +410,11 @@ class _MarkAttendanceWidgetState extends State { if (attendanceType == "NFC") { performNfcAttendance(widget.model, lat: location.latitude.toString() ?? "", lng: location.longitude.toString() ?? ""); } + + if (attendanceType == "location") { + performLocationAttendance(widget.model, lat: location.latitude.toString() ?? "", lng: location.longitude.toString() ?? ""); + } + requestCode = 0; }, ); @@ -506,7 +564,7 @@ class _MarkAttendanceWidgetState extends State { if (isConnected && AppState().isAuthenticated) { await WiFiForIoTPlugin.forceWifiUsage(true); - await Future.delayed(const Duration(seconds: 6)); + // 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); @@ -547,6 +605,37 @@ class _MarkAttendanceWidgetState extends State { } } + Future performLocationAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async { + Utils.showLoading(context); + try { + GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 3, nfcValue: "", isGpsRequired: isWifiLocationEnabled, lat: lat, long: lng); + Utils.hideLoading(context); + if (g?.messageStatus == 2) { + showDialog( + barrierDismissible: true, + context: context, + builder: (cxt) => ConfirmDialog( + message: g?.errorEndUserMessage ?? "", + onTap: () { + Navigator.pop(context); + }, + onCloseTap: () {}, + ), + ); + } else { + showMDialog( + context, + backgroundColor: Colors.transparent, + isDismissable: false, + child: SuccessDialog(widget.isFromDashboard), + ); + } + } catch (ex) { + Utils.hideLoading(context); + Utils.handleException(ex, context, null); + } + } + Future closeWifiRequest() async { if (Platform.isAndroid) { await WiFiForIoTPlugin.forceWifiUsage(false); diff --git a/pubspec.yaml b/pubspec.yaml index 4194812..27c25e5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -66,7 +66,7 @@ dependencies: month_picker_dialog: ^2.12.0 # open_file: ^3.2.1 open_filex: ^4.4.0 - wifi_iot: ^0.3.18 + wifi_iot: ^0.3.19+1 flutter_html: ^3.0.0-alpha.6 # flutter_barcode_scanner: ^2.0.0 qr_code_scanner: ^1.0.1