You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cloudsolutions-atoms/lib/new_views/swipe_module/mark_attendance_widget.dart

822 lines
35 KiB
Dart

// import 'dart:async';
// import 'dart:developer';
// import 'dart:io';
//
// import 'package:flutter/material.dart';
// import 'package:geolocator/geolocator.dart';
// import 'package:huawei_location/huawei_location.dart';
// import 'package:nfc_manager/nfc_manager.dart';
// import 'package:permission_handler/permission_handler.dart';
// import 'package:provider/provider.dart';
// import 'package:test_sa/controllers/providers/api/user_provider.dart';
// import 'package:test_sa/extensions/int_extensions.dart';
// import 'package:test_sa/extensions/text_extensions.dart';
// import 'package:test_sa/extensions/widget_extensions.dart';
// import 'package:test_sa/new_views/app_style/app_color.dart';
// import 'package:test_sa/new_views/pages/land_page/nfc/nfc_reader_sheet.dart';
// import 'package:test_sa/new_views/swipe_module/dialoge/confirm_dialog.dart';
// import 'package:test_sa/new_views/swipe_module/dialoge/qr_scanner_dialog.dart';
// import 'package:test_sa/new_views/swipe_module/dialoge/success_dialog.dart';
// import 'package:test_sa/new_views/swipe_module/enums/swipe_type.dart';
// import 'package:test_sa/new_views/swipe_module/models/swipe_model.dart';
// import 'package:test_sa/new_views/swipe_module/swipe_success_view.dart';
// import 'package:test_sa/new_views/swipe_module/utils/location_utils.dart';
// import 'package:test_sa/new_views/swipe_module/utils/swipe_general_utils.dart';
// import 'package:wifi_iot/wifi_iot.dart';
// todo @sikander delete this file after compelte
// class MarkAttendanceWidget extends StatefulWidget {
// double topPadding;
// bool isFromDashboard;
//
// MarkAttendanceWidget({Key key, this.topPadding = 0, this.isFromDashboard = false}) : super(key: key);
//
// // todo MarkAttendanceWidget(this.model, {Key? key, this.topPadding = 0, this.isFromDashboard = false}) : super(key: key);
//
// @override
// _MarkAttendanceWidgetState createState() {
// return _MarkAttendanceWidgetState();
// }
// }
//
// class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
// bool isNfcEnabled = false, isQrEnabled = false, isWifiEnabled = false;
// UserProvider _userProvider;
//
// int _locationUpdateCbId = 0;
//
// @override
// void initState() {
// super.initState();
// checkAttendanceAvailability();
// }
//
// void checkAttendanceAvailability() async {
// _userProvider = Provider.of<UserProvider>(context, listen: false);
// bool isAvailable = await NfcManager.instance.isAvailable();
// log('backend enabled values are nfc ${_userProvider.user.enableNFC} qr ${_userProvider.user.enableQR} wifi ${_userProvider.user.enableWifi}');
// setState(() {
// if (isAvailable && _userProvider.user.enableNFC) isNfcEnabled = true;
// if (_userProvider.user.enableQR) isQrEnabled = true;
// if (_userProvider.user.enableWifi) isWifiEnabled = true;
// });
// }
//
// void checkHuaweiLocationPermission(SwipeTypeEnum attendanceType, BuildContext context) async {
// // Permission_Handler permissionHandler = PermissionHandler();
// LocationUtilities.isEnabled((bool isEnabled) async {
// if (isEnabled) {
// LocationUtilities.havePermission((bool permission) async {
// if (permission) {
// getHuaweiCurrentLocation(attendanceType, context);
// } else {
// bool has = await requestPermissions();
// if (has) {
// getHuaweiCurrentLocation(attendanceType, context);
// } else {
// showDialog(
// context: context,
// builder: (BuildContext cxt) => ConfirmDialog(
// message: "You need to give location permission to mark attendance",
// onTap: () {
// Navigator.pop(context);
// },
// ),
// );
// }
// }
// });
// } 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 (await permissionHandler.hasLocationPermission()) {
// // getHuaweiCurrentLocation(attendanceType);
// // } else {
// // bool has = await requestPermissions();
// // if (has) {
// // getHuaweiCurrentLocation(attendanceType);
// // } else {
// // showDialog(
// // context: context,
// // builder: (BuildContext cxt) => ConfirmDialog(
// // message: "You need to give location permission to mark attendance",
// // onTap: () {
// // Navigator.pop(context);
// // },
// // ),
// // );
// // }
// // }
// }
//
// Future<bool> requestPermissions() async {
// var result = await [
// Permission.location,
// ].request();
// return (result[Permission.location] == PermissionStatus.granted || result[Permission.locationAlways] == PermissionStatus.granted);
// }
//
// @override
// void dispose() {
// super.dispose();
// // Stop Session
// NfcManager.instance.stopSession();
// }
//
// @override
// Widget build(BuildContext context) {
// return Container(
// padding: EdgeInsets.only(left: 21, right: 21, bottom: 21, top: widget.topPadding),
// decoration: const BoxDecoration(borderRadius: BorderRadius.only(topLeft: Radius.circular(25), topRight: Radius.circular(25)), color: Colors.white),
// width: double.infinity,
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisSize: MainAxisSize.min,
// children: [
// 20.height,
// 'click me '.heading5(context),
// // LocaleKeys.markAttendance.tr().toSectionHeading(),
// // LocaleKeys.selectMethodOfAttendance.tr().toText11(color: const Color(0xff535353)),
// GridView(
// physics: const NeverScrollableScrollPhysics(),
// shrinkWrap: true,
// padding: const EdgeInsets.only(bottom: 0, top: 21),
// gridDelegate:
// SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: (MediaQuery.of(context).size.width < 550) ? 3 : 5, childAspectRatio: 1 / 1, crossAxisSpacing: 8, mainAxisSpacing: 8),
// children: availableAttendanceMethodList(context: context),
// )
// ],
// ),
// );
// }
//
// void handleSwipe({
// SwipeTypeEnum swipeType,
// @required bool isEnable,
// @required BuildContext context,
// }) {
// // if (AppState().getIsHuawei) {
// if (false) {
// checkHuaweiLocationPermission(swipeType, context);
// } else {
// LocationUtilities.isEnabled((bool isEnabled) {
// if (isEnabled) {
// LocationUtilities.havePermission((bool permission) {
// if (permission) {
// SwipeGeneralUtils.showLoading(context);
// LocationUtilities.getCurrentLocation(
// (Position position, bool isMocked) {
// if (isMocked) {
// SwipeGeneralUtils.hideLoading(context);
// SwipeGeneralUtils.markFakeAttendance(swipeType.name, position.latitude.toString() ?? "", position.longitude.toString() ?? "", context);
// } else {
// SwipeGeneralUtils.hideLoading(context);
// //todo performNfcAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? "");
// handleSwipeOperation(swipeType: swipeType, lat: position.latitude, lang: position.longitude);
// }
// },
// () {
// SwipeGeneralUtils.hideLoading(context);
// SwipeGeneralUtils.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();
// },
// ),
// );
// }
// });
// }
// }
//
// void handleSwipeOperation({@required SwipeTypeEnum swipeType, double lat, double lang, BuildContext context}) {
// switch (swipeType) {
// case SwipeTypeEnum.NFC:
// handleNfcAttendance(latitude: lat, longitude: lang, context: context);
// return;
// case SwipeTypeEnum.QR:
// performQrCodeAttendance(latitude: lat, longitude: lang, context: context);
// return;
// case SwipeTypeEnum.Wifi:
// //TODO need to implement.
// return;
// }
// }
//
// void getHuaweiCurrentLocation(SwipeTypeEnum attendanceType, BuildContext context) async {
// try {
// SwipeGeneralUtils.showLoading(context);
// FusedLocationProviderClient locationService = FusedLocationProviderClient()..initFusedLocationService();
// LocationRequest locationRequest = LocationRequest();
// locationRequest.priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
// locationRequest.interval = 500;
// List<LocationRequest> locationRequestList = <LocationRequest>[locationRequest];
// LocationSettingsRequest locationSettingsRequest = LocationSettingsRequest(requests: locationRequestList);
//
// StreamSubscription<Location> _streamSubscription;
// int requestCode = (await (locationService.requestLocationUpdates(locationRequest)));
//
// _streamSubscription = locationService.onLocationData.listen(
// (Location location) async {
// SwipeGeneralUtils.hideLoading(context);
// await locationService.removeLocationUpdates(requestCode);
// handleSwipeOperation(swipeType: attendanceType);
// requestCode = 0;
// },
// );
//
// // locationService.checkLocationSettings(locationSettingsRequest).then((settings) async {
// // await locationService.getLastLocation().then((value) {
// // if (value.latitude == null || value.longitude == null) {
// // showDialog(
// // context: context,
// // builder: (BuildContext cxt) => ConfirmDialog(
// // message: "Unable to get your location, Please check your location settings & try again.",
// // onTap: () {
// // Navigator.pop(context);
// // },
// // ),
// // );
// // } else {
// // if (attendanceType == "QR") {
// // performQrCodeAttendance(widget.model, lat: value.latitude.toString() ?? "", lng: value.longitude.toString() ?? "");
// // }
// // if (attendanceType == "WIFI") {
// // performWifiAttendance(widget.model, lat: value.latitude.toString() ?? "", lng: value.longitude.toString() ?? "");
// // }
// // if (attendanceType == "NFC") {
// // performNfcAttendance(widget.model, lat: value.latitude.toString() ?? "", lng: value.longitude.toString() ?? "");
// // }
// // }
// // }).catchError((error) {
// // log("HUAWEI LOCATION getLastLocation ERROR!!!!!");
// // log(error);
// // });
// // }).catchError((error) {
// // log("HUAWEI LOCATION checkLocationSettings ERROR!!!!!");
// // log(error);
// // if (error.code == "LOCATION_SETTINGS_NOT_AVAILABLE") {
// // // Location service not enabled.
// // }
// // });
// } catch (error) {
// log("HUAWEI LOCATION ERROR!!!!!");
// log('$error');
// SwipeGeneralUtils.hideLoading(context);
// // SwipeGeneralUtils.handleException(error, context, null);
// }
// }
//
// Future<void> handleNfcAttendance({double latitude = 0, double longitude = 0, BuildContext context}) async {
// final userProvider = Provider.of<UserProvider>(context, listen: false);
//
// if (Platform.isIOS) {
// SwipeGeneralUtils.readNFc(onRead: (String nfcId) async {
// await _processNfcAttendance(userProvider, nfcId, latitude, longitude, context);
// });
// } else {
// showNfcReader(context, onNcfScan: (String nfcId) async {
// await _processNfcAttendance(userProvider, nfcId ?? '', latitude, longitude, context);
// });
// }
// }
//
// Future<void> _processNfcAttendance(
// UserProvider userProvider,
// String nfcId,
// double latitude,
// double longitude,
// BuildContext context,
// ) async {
// SwipeGeneralUtils.showLoading(context);
// try {
// // final swipeModel = Swipe(
// // swipeTypeValue: SwipeTypeEnum.NFC.getIntFromSwipeTypeEnum(),
// // value: nfcId,
// // latitude: latitude,
// // longitude: longitude,
// // );
// //Test model...
// final swipeModel = Swipe(swipeTypeValue: SwipeTypeEnum.NFC.getIntFromSwipeTypeEnum(), value: '123', latitude: 24.70865415364271, longitude: 46.66600861881879);
// final swipeResponse = await userProvider.makeSwipe(model: swipeModel);
// if (swipeResponse.isSuccess) {
// if (Platform.isIOS) await Future.delayed(const Duration(seconds: 3));
// SwipeGeneralUtils.hideLoading(context);
// Navigator.pushNamed(context, SwipeSuccessView.routeName);
// } else {
// SwipeGeneralUtils.hideLoading(context);
// SwipeGeneralUtils.showErrorDialog(message: swipeResponse.message ?? "Unexpected error occurred", context: context);
// }
// } catch (errSwipeGeneralUtilsor) {
// SwipeGeneralUtils.hideLoading(context);
// // Uncomment below line for error handling if needed
// // SwipeGeneralUtils.handleException(error, context, null);
// }
// }
//
// Future<bool> closeWifiRequest() async {
// if (Platform.isAndroid) {
// await WiFiForIoTPlugin.forceWifiUsage(false);
// }
// return await WiFiForIoTPlugin.disconnect();
// }
//
// Future<void> performQrCodeAttendance({double latitude, double longitude, BuildContext context}) async {
// UserProvider userProvider = Provider.of<UserProvider>(context, listen: false);
// var qrCodeValue = await Navigator.of(context).push(
// MaterialPageRoute(
// builder: (BuildContext context) => QrScannerDialog(),
// ),
// );
// if (qrCodeValue != null) {
// SwipeGeneralUtils.showLoading(context);
// try {
// //test model..
// final swipeModel = Swipe(
// swipeTypeValue: SwipeTypeEnum.QR.getIntFromSwipeTypeEnum(),
// value: '2323',
// latitude: 24.70865415364271,
// longitude: 46.66600861881879,
// );
// final swipeResponse = await userProvider.makeSwipe(model: swipeModel);
// if (swipeResponse.isSuccess) {
// SwipeGeneralUtils.hideLoading(context);
// SwipeGeneralUtils.showMDialog(context, backgroundColor: Colors.transparent, isDismissable: true, child: SuccessDialog(widget.isFromDashboard));
// } else {
// SwipeGeneralUtils.hideLoading(context);
// showDialog(
// barrierDismissible: true,
// context: context,
// builder: (cxt) => ConfirmDialog(
// message: swipeResponse.message ?? "",
// onTap: () {
// Navigator.pop(context);
// },
// onCloseTap: () {}
// ),
// );
// }
// } catch (ex) {
// SwipeGeneralUtils.hideLoading(context);
// }
// }
// }
//
// List<Widget> availableAttendanceMethodList({@required BuildContext context}) {
// List<Widget> availableMethods = [];
// if (isNfcEnabled) {
// availableMethods.add(attendanceMethod(SwipeTypeEnum.NFC.name, 'nfc_icon', isNfcEnabled, () {
// handleSwipe(swipeType: SwipeTypeEnum.NFC, isEnable: isNfcEnabled, context: context);
// }));
// }
// if (isQrEnabled) {
// availableMethods.add(attendanceMethod(SwipeTypeEnum.QR.name, 'wifi_icon', isQrEnabled, () {
// handleSwipe(swipeType: SwipeTypeEnum.QR, isEnable: isQrEnabled, context: context);
// }));
// }
// if (isWifiEnabled) {
// availableMethods.add(attendanceMethod(SwipeTypeEnum.Wifi.name, 'wifi_icon', isWifiEnabled, () {
// handleSwipe(swipeType: SwipeTypeEnum.Wifi, isEnable: isWifiEnabled, context: context);
// }));
// }
// return availableMethods;
// }
//
// Widget attendanceMethod(String title, String icon, bool isEnabled, VoidCallback onPress) {
// return Container(
// padding: EdgeInsets.all(12),
// decoration: BoxDecoration(
// color: Colors.white,
// borderRadius: BorderRadius.circular(18),
// border: Border.all(color: AppColor.white40, width: 2),
// ),
// child: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// icon.toSvgAsset(),
// title.heading5(context).custom(color: AppColor.neutral50),
// // Text(
// // title,
// // style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500),
// // ),
// ],
// ),
// ).onPress(
// () {
// log('isEnabled is ${!isEnabled}');
// if (!isEnabled) return;
// onPress();
// },
// );
// // return Container(
// // decoration: BoxDecoration(
// // borderRadius: BorderRadius.circular(15),
// // color: isEnabled ? null : Colors.grey.withOpacity(.5),
// // gradient: isEnabled
// // ? const LinearGradient(
// // transform: GradientRotation(.64),
// // begin: Alignment.topRight,
// // end: Alignment.bottomLeft,
// // colors: [
// // //ToDo set Colors according to design provided by designer...
// // Colors.blue,
// // Colors.green,
// // // AppColor.gradiantEndColor,
// // // MyColors.gradiantStartColor,
// // ],
// // )
// // : null,
// // ),
// // clipBehavior: Clip.antiAlias,
// // padding: const EdgeInsets.only(left: 10, right: 10, top: 14, bottom: 14),
// // child: Column(
// // crossAxisAlignment: CrossAxisAlignment.start,
// // children: [
// // // SvgPicture.asset(image, color: Colors.white, alignment: Alignment.topLeft).expanded,
// // Icon(iconData, color: isEnabled ? AppColor.black35 : Colors.grey),
// // title.heading6(context),
// // // title.toText17(isBold: true, color: Colors.white),
// // ],
// // ),
// // ).onPress(
// // () {
// // log('isEnabled is ${!isEnabled}');
// // if (!isEnabled) return;
// // onPress();
// // },
// // );
// }
// }
//
// // Widget customListItem({required String icon, required String heading, required String subHeading, required VoidCallback onTap}) {
// // return GestureDetector(
// // onTap: onTap, // Handles the tap
// // child: Card(
// // shape: RoundedRectangleBorder(
// // borderRadius: BorderRadius.circular(14), // Circular border radius
// // ),
// // color: Colors.white,
// // child: Row(
// // crossAxisAlignment: CrossAxisAlignment.start, // Align items at the top
// // children: [
// // // Icon Section
// // icon
// // .toSvgAsset(
// // width: 32,
// // color: AppColor.neutral120,
// // height: 29,
// // )
// // .paddingOnly(top: 8),
// // 14.width,
// // Expanded(
// // child: Column(
// // crossAxisAlignment: CrossAxisAlignment.start,
// // children: [
// // Text(
// // heading,
// // style: AppTextStyles.heading6.copyWith(color: AppColor.neutral50),
// // ),
// // 7.height,
// // Text(
// // subHeading,
// // style: AppTextStyles.bodyText2.copyWith(color: AppColor.neutral120),
// // ),
// // ],
// // ).paddingOnly(end: 50),
// // ),
// // ],
// // ).paddingAll(12),
// // ),
// // );
// // }
//
// //qr older code...
//
// //nfc older code widget
//
// // // if (AppState().getIsHuawei) {
// // if (false) {
// // checkHuaweiLocationPermission(SwipeTypeEnum.NFC);
// // } else {
// // LocationUtilities.isEnabled((bool isEnabled) {
// // if (isEnabled) {
// // LocationUtilities.havePermission((bool permission) {
// // if (permission) {
// // SwipeGeneralUtils.showLoading(context);
// // LocationUtilities.getCurrentLocation(
// // (Position position, bool isMocked) {
// // if (isMocked) {
// // SwipeGeneralUtils.hideLoading(context);
// // SwipeGeneralUtils.markFakeAttendance("NFC", position.latitude.toString() ?? "", position.longitude.toString() ?? "",context);
// // } else {
// // SwipeGeneralUtils.hideLoading(context);
// // //todo performNfcAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? "");
// // }
// // },
// // () {
// // SwipeGeneralUtils.hideLoading(context);
// // SwipeGeneralUtils.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();
// // },
// // ),
// // );
// // }
// // });
// // }
//
// //older code....
// // Future<void> performNfcAttendance({double lat = 0, double lng = 0}) async {
// // UserProvider userProvider = Provider.of<UserProvider>(context,listen:false);
// // if (Platform.isIOS) {
// // SwipeGeneralUtils.readNFc(onRead: (String nfcId) async {
// // SwipeGeneralUtils.showLoading(context);
// // try {
// // SwipeModel swipeResponse = await userProvider.makeSwipe(model: Swipe(swipeTypeValue: SwipeTypeEnum.NFC.getIntFromSwipeTypeEnum(), value: '', latitude: lat, longitude: lng));
// // if (swipeResponse.responseCode != 1) {
// // SwipeGeneralUtils.hideLoading(context);
// // showDialog(
// // context: context,
// // builder: (BuildContext cxt) => ConfirmDialog(
// // message: swipeResponse.message ?? "Unexpected error occurred",
// // onTap: () {
// // Navigator.pop(context);
// // },
// // ),
// // );
// // } else {
// // bool status = swipeResponse.data;
// // if (Platform.isIOS) await Future.delayed(const Duration(seconds: 3));
// // SwipeGeneralUtils.hideLoading(context);
// // SwipeGeneralUtils.showMDialog(
// // context,
// // backgroundColor: Colors.transparent,
// // isDismissable: true,
// // child: SuccessDialog(widget.isFromDashboard),
// // );
// // }
// // } catch (ex) {
// // SwipeGeneralUtils.hideLoading(context);
// // // SwipeGeneralUtils.handleException(ex, context, null);
// // }
// // });
// // } else {
// // showNfcReader(context, onNcfScan: (String nfcId) async {
// // SwipeGeneralUtils.showLoading(context);
// // try {
// // SwipeModel swipeResponse = await userProvider.makeSwipe(model: Swipe(swipeTypeValue: SwipeTypeEnum.NFC.getIntFromSwipeTypeEnum(), value: nfcId??'', latitude: lat, longitude: lng));
// // log('api response i got is ${swipeResponse.toJson()}');
// // if (swipeResponse.responseCode != 1) {
// // SwipeGeneralUtils.hideLoading(context);
// // showDialog(
// // context: context,
// // builder: (BuildContext cxt) => ConfirmDialog(
// // message: swipeResponse.message ?? "Unexpected error occurred",
// // onTap: () {
// // Navigator.pop(context);
// // },
// // ),
// // );
// // } else {
// // bool status = swipeResponse.data; //use this status to get transactions.
// // if (Platform.isIOS) await Future.delayed(const Duration(seconds: 3));
// // SwipeGeneralUtils.hideLoading(context);
// // SwipeGeneralUtils.showMDialog(
// // context,
// // backgroundColor: Colors.transparent,
// // isDismissable: true,
// // child: SuccessDialog(widget.isFromDashboard),
// // );
// // }
// // } catch (ex) {
// // SwipeGeneralUtils.hideLoading(context);
// // // SwipeGeneralUtils.handleException(ex, context, null);
// // }
// // // SwipeGeneralUtils.showLoading(context);
// // // try {
// // // GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 2, nfcValue: nfcId ?? "", isGpsRequired: isNfcLocationEnabled, lat: lat, long: lng);
// // // if (g?.messageStatus != 1) {
// // // SwipeGeneralUtils.hideLoading(context);
// // // showDialog(
// // // context: context,
// // // builder: (BuildContext cxt) => ConfirmDialog(
// // // message: g?.errorEndUserMessage ?? "Unexpected error occurred",
// // // onTap: () {
// // // Navigator.pop(context);
// // // },
// // // ),
// // // );
// // // } else {
// // // bool status = await model.fetchAttendanceTracking(context);
// // // SwipeGeneralUtils.hideLoading(context);
// // // showMDialog(
// // // context,
// // // backgroundColor: Colors.transparent,
// // // isDismissable: false,
// // // child: SuccessDialog(widget.isFromDashboard),
// // // );
// // // }
// // // } catch (ex) {
// // // log(ex);
// // // SwipeGeneralUtils.hideLoading(context);
// // // // SwipeGeneralUtils.handleException(ex, context, (String msg) {
// // // // SwipeGeneralUtils.confirmDialog(context, msg);
// // // // });
// // // }
// // });
// // }
// // }
//
// //
// // Future<bool> checkSession() async {
// // try {
// // SwipeGeneralUtils.showLoading(context);
// // await DashboardApiClient().getOpenMissingSwipes();
// // SwipeGeneralUtils.hideLoading(context);
// // return true;
// // } catch (ex) {
// // SwipeGeneralUtils.hideLoading(context);
// // SwipeGeneralUtils.handleException(ex, context, null);
// // return false;
// // }
// // }
//
// //TODO need to confirm ....
// Future<void> performWifiAttendance({double? latitude, double? lng}) async {
// // if (Platform.isAndroid) {
// // if (!(await checkSession())) {
// // return;
// // }
// // }
// SwipeGeneralUtils.showLoading(context);
// bool isConnected = await WiFiForIoTPlugin.connect(AppState().getMohemmWifiSSID ?? "",
// password: AppState().getMohemmWifiPassword ?? "", joinOnce: Platform.isIOS ? false : true, security: NetworkSecurity.WPA, withInternet: false);
//
// if (Platform.isIOS) {
// if (await WiFiForIoTPlugin.getSSID() == AppState().getMohemmWifiSSID) {
// isConnected = true;
// } else {
// isConnected = false;
// }
// }
//
// if (isConnected && AppState().isAuthenticated) {
// 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);
// SwipeGeneralUtils.hideLoading(context);
// await closeWifiRequest();
// 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) {
// await closeWifiRequest();
// SwipeGeneralUtils.hideLoading(context);
// SwipeGeneralUtils.handleException(ex, context, null);
// }
// } else {
// if (AppState().isAuthenticated) {
// SwipeGeneralUtils.hideLoading(context);
// SwipeGeneralUtils.confirmDialog(context, "LocaleKeys.comeNearHMGWifi.tr()");
// } else {
// await closeWifiRequest();
// }
// }
// }
//
// // older grid widget..
// // attendanceMethod(SwipeTypeEnum.NFC.name, Icons.nfc, isNfcEnabled, () {
// // handleSwipe(swipeType: SwipeTypeEnum.NFC, isEnable: isNfcEnabled);
// // }),
// // attendanceMethod(SwipeTypeEnum.QR.name, Icons.qr_code_2, isQrEnabled, () async {
// // handleSwipe(swipeType: SwipeTypeEnum.QR, isEnable: true);
// // }),
// // //if (isWifiEnabled) //todo
// // attendanceMethod(SwipeTypeEnum.Wifi.name, Icons.wifi, isWifiEnabled, () {
// // // if (AppState().getIsHuawei) {
// // if (false) {
// // checkHuaweiLocationPermission(SwipeTypeEnum.Wifi);
// // } else {
// // LocationUtilities.isEnabled((bool isEnabled) {
// // if (isEnabled) {
// // LocationUtilities.havePermission((bool permission) {
// // if (permission) {
// // SwipeGeneralUtils.showLoading(context);
// // LocationUtilities.getCurrentLocation(
// // (Position position, bool isMocked) {
// // if (isMocked) {
// // SwipeGeneralUtils.hideLoading(context);
// // SwipeGeneralUtils.markFakeAttendance("WIFI", position.latitude.toString() ?? "", position.longitude.toString() ?? "", context);
// // } else {
// // SwipeGeneralUtils.hideLoading(context);
// // //todo performWifiAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? "");
// // }
// // },
// // () {
// // SwipeGeneralUtils.hideLoading(context);
// // SwipeGeneralUtils.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();
// // },
// // ),
// // );
// // }
// // });
// // }
// // }),