diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 32b3fc7..45ef661 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -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/"; diff --git a/lib/widgets/location/Location.dart b/lib/widgets/location/Location.dart index 62bd016..e324618 100644 --- a/lib/widgets/location/Location.dart +++ b/lib/widgets/location/Location.dart @@ -8,7 +8,7 @@ import 'package:mohem_flutter_app/classes/utils.dart'; class Location { static void havePermission(Function(bool) callback) { Geolocator.checkPermission().then((value) async { - if (value == LocationPermission.denied) { + if (value == LocationPermission.denied || value == LocationPermission.deniedForever) { value = await Geolocator.requestPermission(); callback(![LocationPermission.denied, LocationPermission.deniedForever].contains(value)); } else { diff --git a/lib/widgets/mark_attendance_widget.dart b/lib/widgets/mark_attendance_widget.dart index f11fafe..dfb4357 100644 --- a/lib/widgets/mark_attendance_widget.dart +++ b/lib/widgets/mark_attendance_widget.dart @@ -54,8 +54,6 @@ class _MarkAttendanceWidgetState extends State { } void checkAttendanceAvailability() async { - String? deviceID = await PlatformDeviceId.getDeviceId; - print("Platform Device ID: $deviceID"); bool isAvailable = await NfcManager.instance.isAvailable(); setState(() { AppState().privilegeListModel!.forEach((PrivilegeListModel element) { @@ -124,7 +122,7 @@ class _MarkAttendanceWidgetState extends State { mainAxisSize: MainAxisSize.min, children: [ LocaleKeys.markAttendance.tr().toSectionHeading(), - LocaleKeys.selectMethodOfAttendance.tr().tr().toText11(color: const Color(0xff535353)), + LocaleKeys.selectMethodOfAttendance.tr().toText11(color: const Color(0xff535353)), GridView( physics: const NeverScrollableScrollPhysics(), shrinkWrap: true, @@ -132,60 +130,145 @@ class _MarkAttendanceWidgetState extends State { gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: (MediaQuery.of(context).size.width < 550) ? 3 : 5, childAspectRatio: 1 / 1, crossAxisSpacing: 8, mainAxisSpacing: 8), children: [ - // if (isNfcEnabled) attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, () { - // if (isNfcLocationEnabled) { + if (AppState().getIsHuawei) { + checkHuaweiLocationPermission("NFC"); + } else { + Location.isEnabled((bool isEnabled) { + if (isEnabled) { + Location.havePermission((bool permission) { + if (permission) { + Location.getCurrentLocation( + (Position position, bool isMocked) { + if (isMocked) { + markFakeAttendance("NFC", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); + } else { + performNfcAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? ""); + } + }, + 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(); + }, + ), + ); + } + }); + } + }), + if (isWifiEnabled) + attendanceMethod("Wifi", "assets/images/wufu.svg", isWifiEnabled, () { if (AppState().getIsHuawei) { - checkHuaweiLocationPermission("NFC"); + checkHuaweiLocationPermission("WIFI"); } else { - Location.getCurrentLocation((Position position, bool isMocked) { - if (isMocked) { - markFakeAttendance("NFC", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); + Location.isEnabled((bool isEnabled) { + if (isEnabled) { + Location.havePermission((bool permission) { + if (permission) { + Location.getCurrentLocation( + (Position position, bool isMocked) { + if (isMocked) { + markFakeAttendance("WIFI", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); + } else { + performWifiAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? ""); + } + }, + 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 { - performNfcAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? ""); + 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(); + }, + ), + ); } - }, context); + }); } - // } else { - // performNfcAttendance(widget.model); - // } - }), - if (isWifiEnabled) - attendanceMethod("Wifi", "assets/images/wufu.svg", isWifiEnabled, () { - // if (isWifiLocationEnabled) { - if (AppState().getIsHuawei) { - checkHuaweiLocationPermission("WIFI"); - } else { - Location.getCurrentLocation((Position position, bool isMocked) { - if (isMocked) { - markFakeAttendance("WIFI", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); - } else { - performWifiAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? ""); - } - }, context); - } - // } else { - // performWifiAttendance(widget.model); - // } }), if (isQrEnabled) attendanceMethod("QR", "assets/images/ic_qr.svg", isQrEnabled, () async { - // if (isQrLocationEnabled) { - if (AppState().getIsHuawei) { - checkHuaweiLocationPermission("QR"); - } else { - Location.getCurrentLocation((Position position, bool isMocked) { - if (isMocked) { - markFakeAttendance("QR", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); - } else { - performQrCodeAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? ""); - } - }, context); - } - // } else { - // performQrCodeAttendance(widget.model); - // } - // performQrCodeAttendance(model); + if (AppState().getIsHuawei) { + checkHuaweiLocationPermission("QR"); + } else { + Location.isEnabled((bool isEnabled) { + if (isEnabled) { + Location.havePermission((bool permission) { + if (permission) { + Location.getCurrentLocation( + (Position position, bool isMocked) { + if (isMocked) { + markFakeAttendance("QR", position.latitude.toString() ?? "", position.longitude.toString() ?? ""); + } else { + performQrCodeAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? ""); + } + }, + 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(); + }, + ), + ); + } + }); + } }), ], )