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.
867 lines
37 KiB
Dart
867 lines
37 KiB
Dart
// import 'dart:async';
|
|
// import 'dart:developer';
|
|
// import 'dart:io';
|
|
//
|
|
// import 'package:flutter/material.dart';
|
|
// import 'package:flutter_svg/flutter_svg.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/dashboard_latest/dashboard_provider.dart';
|
|
// // import 'package:platform_device_id/platform_device_id.dart';
|
|
// import 'package:test_sa/dashboard_latest/widgets/app_bar_widget.dart';
|
|
// import 'package:test_sa/extensions/enum_extensions.dart';
|
|
// import 'package:test_sa/extensions/text_extensions.dart';
|
|
// import 'package:test_sa/extensions/widget_extensions.dart';
|
|
// import 'package:test_sa/helper/utils.dart';
|
|
// import 'package:test_sa/models/enums/swipe_type.dart';
|
|
// import 'package:test_sa/models/lookup.dart';
|
|
// import 'package:test_sa/models/new_models/swipe_model.dart';
|
|
// import 'package:test_sa/nfc/nfc_reader_sheet.dart';
|
|
// import 'package:test_sa/utilities/Location.dart' as location;
|
|
// import 'package:test_sa/views/widgets/dialogs/confirm_dialog.dart';
|
|
// import 'package:test_sa/views/widgets/dialogs/success_dialog.dart';
|
|
// import 'package:test_sa/views/widgets/qr_scanner_dialog.dart';
|
|
// import 'package:wifi_iot/wifi_iot.dart';
|
|
//
|
|
// import '../../app_style/app_color.dart';
|
|
//
|
|
// class MarkAttendanceWidget extends StatefulWidget {
|
|
// // DashboardProviderModel model;
|
|
// 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, isNfcLocationEnabled = false, isQrEnabled = false, isQrLocationEnabled = false, isWifiEnabled = false, isWifiLocationEnabled = false;
|
|
//
|
|
// int _locationUpdateCbId = 0;
|
|
//
|
|
// @override
|
|
// void initState() {
|
|
// super.initState();
|
|
// checkAttendanceAvailability();
|
|
// }
|
|
//
|
|
// void checkAttendanceAvailability() async {
|
|
// bool isAvailable = await NfcManager.instance.isAvailable();
|
|
// // setState(() {
|
|
// // AppState().privilegeListModel!.forEach((PrivilegeListModel element) {
|
|
// // if (element.serviceName == "enableNFC") {
|
|
// // if (isAvailable) if (element.previlege ?? false) isNfcEnabled = true;
|
|
// // } else if (element.serviceName == "enableQR") {
|
|
// // if (element.previlege ?? false) isQrEnabled = true;
|
|
// // } else if (element.serviceName == "enableWIFI") {
|
|
// // if (element.previlege ?? false) isWifiEnabled = true;
|
|
// // } else if (element.serviceName!.trim() == "enableLocationNFC") {
|
|
// // if (element.previlege ?? false) isNfcLocationEnabled = true;
|
|
// // } else if (element.serviceName == "enableLocationQR") {
|
|
// // if (element.previlege ?? false) isQrLocationEnabled = true;
|
|
// // } else if (element.serviceName == "enableLocationWIFI") {
|
|
// // if (element.previlege ?? false) isWifiLocationEnabled = true;
|
|
// // }
|
|
// // });
|
|
// // });
|
|
// }
|
|
//
|
|
// void checkHuaweiLocationPermission(String attendanceType) async {
|
|
// // Permission_Handler permissionHandler = PermissionHandler();
|
|
// location.Location.isEnabled((bool isEnabled) async {
|
|
// if (isEnabled) {
|
|
// location.Location.havePermission((bool permission) async {
|
|
// if (permission) {
|
|
// 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);
|
|
// },
|
|
// ),
|
|
// );
|
|
// }
|
|
// }
|
|
// });
|
|
// } 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: [
|
|
// // 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: <Widget>[
|
|
// attendanceMethod(SwipeTypeEnum.NFC.name, Icons.nfc, true, () {
|
|
// log('i am here...nfc');
|
|
// handleSwipe(swipeType: SwipeTypeEnum.NFC, isEnable: true);
|
|
// return;
|
|
// // if (AppState().getIsHuawei) {
|
|
// if (false) {
|
|
// checkHuaweiLocationPermission("NFC");
|
|
// } 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("NFC", position.latitude.toString() ?? "", position.longitude.toString() ?? "");
|
|
// } else {
|
|
// Utils.hideLoading(context);
|
|
// //todo 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 {
|
|
// 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) //todo
|
|
// attendanceMethod("Wifi", Icons.wifi, isWifiEnabled, () {
|
|
// // if (AppState().getIsHuawei) {
|
|
// if (false) {
|
|
// checkHuaweiLocationPermission("WIFI");
|
|
// } 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("WIFI", position.latitude.toString() ?? "", position.longitude.toString() ?? "");
|
|
// } else {
|
|
// Utils.hideLoading(context);
|
|
// //todo 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 {
|
|
// 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 (isQrEnabled) //todo
|
|
// attendanceMethod(SwipeTypeEnum.QR.name, Icons.qr_code_2, true, () async {
|
|
// handleSwipe(swipeType: SwipeTypeEnum.QR, isEnable: true);
|
|
// return;
|
|
// // if (AppState().getIsHuawei) {
|
|
// if (false) {
|
|
// checkHuaweiLocationPermission("QR");
|
|
// } 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("QR", position.latitude.toString() ?? "", position.longitude.toString() ?? "");
|
|
// } else {
|
|
// Utils.hideLoading(context);
|
|
// //todo 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 {
|
|
// 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 handleSwipe({required SwipeTypeEnum swipeType,required bool isEnable,}){
|
|
// log('handle swipe value is ${swipeType.name}');
|
|
// // if (AppState().getIsHuawei) {
|
|
// if (false) {
|
|
// checkHuaweiLocationPermission("NFC");
|
|
// } 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(swipeType.name, position.latitude.toString() ?? "", position.longitude.toString() ?? "");
|
|
// } else {
|
|
// Utils.hideLoading(context);
|
|
// //todo performNfcAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? "");
|
|
// handleSwipeOperation(swipeType: swipeType,lat: position.latitude,lang: position.longitude);
|
|
// }
|
|
// },
|
|
// () {
|
|
// 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();
|
|
// },
|
|
// ),
|
|
// );
|
|
// }
|
|
// });
|
|
// }
|
|
// }
|
|
//
|
|
// void handleSwipeOperation({required SwipeTypeEnum swipeType,double ?lat, double ?lang}){
|
|
// switch(swipeType){
|
|
// case SwipeTypeEnum.NFC:
|
|
// handleNfcAttendance(latitude: lat,longitude: lang);
|
|
// return;
|
|
// case SwipeTypeEnum.QR:
|
|
// performQrCodeAttendance(latitude: lat,longitude: lang);
|
|
// return;
|
|
// case SwipeTypeEnum.Wifi:
|
|
// return;
|
|
//
|
|
// }
|
|
// }
|
|
//
|
|
// void getHuaweiCurrentLocation(String attendanceType) async {
|
|
// try {
|
|
// Utils.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);
|
|
//
|
|
// late StreamSubscription<Location> _streamSubscription;
|
|
// int requestCode = (await (locationService.requestLocationUpdates(locationRequest)))!;
|
|
//
|
|
// _streamSubscription = locationService.onLocationData!.listen(
|
|
// (Location location) async {
|
|
// Utils.hideLoading(context);
|
|
// await locationService.removeLocationUpdates(requestCode);
|
|
// if (attendanceType == "QR") {
|
|
// // todo performQrCodeAttendance(widget.model, lat: location.latitude.toString() ?? "", lng: location.longitude.toString() ?? "");
|
|
// }
|
|
// if (attendanceType == "WIFI") {
|
|
// // todo performWifiAttendance(widget.model, lat: location.latitude.toString() ?? "", lng: location.longitude.toString() ?? "");
|
|
// }
|
|
// if (attendanceType == "NFC") {
|
|
// //todo performNfcAttendance(widget.model, lat: location.latitude.toString() ?? "", lng: location.longitude.toString() ?? "");
|
|
// }
|
|
// 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');
|
|
// Utils.hideLoading(context);
|
|
// // Utils.handleException(error, context, null);
|
|
// }
|
|
// }
|
|
//
|
|
// Future<void> handleNfcAttendance({double? latitude = 0, double? longitude = 0}) async {
|
|
// final dashBoardProvider = Provider.of<DashBoardProvider>(context, listen: false);
|
|
//
|
|
// if (Platform.isIOS) {
|
|
// Utils.readNFc(onRead: (String nfcId) async {
|
|
// await _processNfcAttendance(dashBoardProvider, nfcId, latitude, longitude);
|
|
// });
|
|
// } else {
|
|
// showNfcReader(context, onNcfScan: (String? nfcId) async {
|
|
// await _processNfcAttendance(dashBoardProvider, nfcId ?? '', latitude, longitude);
|
|
// });
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
// Future<void> _processNfcAttendance(
|
|
// DashBoardProvider dashBoardProvider,
|
|
// String nfcId,
|
|
// double? latitude,
|
|
// double? longitude,
|
|
// ) async {
|
|
// Utils.showLoading(context);
|
|
// try {
|
|
// final swipeModel = Swipe(
|
|
// swipeTypeValue: SwipeTypeEnum.NFC.getIntFromSwipeTypeEnum(),
|
|
// value: nfcId,
|
|
// latitude: latitude,
|
|
// longitude: longitude,
|
|
// );
|
|
//
|
|
// final swipeResponse = await dashBoardProvider.makeSwipe(model: swipeModel);
|
|
// log('swipe response i got is ${swipeResponse.toJson()}');
|
|
//
|
|
// if (swipeResponse.responseCode != 1) {
|
|
// Utils.hideLoading(context);
|
|
// _showErrorDialog(swipeResponse.message ?? "Unexpected error occurred");
|
|
// } else {
|
|
// final isSuccess = swipeResponse.data;
|
|
// log('nfc swipe response is ${isSuccess}');
|
|
// if (Platform.isIOS) await Future.delayed(const Duration(seconds: 3));
|
|
// Utils.hideLoading(context);
|
|
// _showSuccessDialog();
|
|
// }
|
|
// } catch (error) {
|
|
// Utils.hideLoading(context);
|
|
// // Uncomment below line for error handling if needed
|
|
// // Utils.handleException(error, context, null);
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
// void _showErrorDialog(String message) {
|
|
// showDialog(
|
|
// context: context,
|
|
// builder: (context) => ConfirmDialog(
|
|
// message: message,
|
|
// onTap: () => Navigator.pop(context),
|
|
// ),
|
|
// );
|
|
// }
|
|
//
|
|
// void _showSuccessDialog() {
|
|
// showMDialog(
|
|
// context,
|
|
// backgroundColor: Colors.transparent,
|
|
// isDismissable: true,
|
|
// child: SuccessDialog(widget.isFromDashboard),
|
|
// );
|
|
// }
|
|
//
|
|
//
|
|
// //older code....
|
|
// Future<void> performNfcAttendance({double? lat = 0, double ?lng = 0}) async {
|
|
// DashBoardProvider dashBoardProvider = Provider.of<DashBoardProvider>(context,listen:false);
|
|
// if (Platform.isIOS) {
|
|
// Utils.readNFc(onRead: (String nfcId) async {
|
|
// Utils.showLoading(context);
|
|
// try {
|
|
// SwipeModel? swipeResponse = await dashBoardProvider.makeSwipe(model: Swipe(swipeTypeValue: SwipeTypeEnum.NFC.getIntFromSwipeTypeEnum(), value: '', latitude: lat, longitude: lng));
|
|
// if (swipeResponse.responseCode != 1) {
|
|
// Utils.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));
|
|
// Utils.hideLoading(context);
|
|
// showMDialog(
|
|
// context,
|
|
// backgroundColor: Colors.transparent,
|
|
// isDismissable: true,
|
|
// child: SuccessDialog(widget.isFromDashboard),
|
|
// );
|
|
// }
|
|
// } catch (ex) {
|
|
// Utils.hideLoading(context);
|
|
// // Utils.handleException(ex, context, null);
|
|
// }
|
|
// });
|
|
// } else {
|
|
// showNfcReader(context, onNcfScan: (String? nfcId) async {
|
|
// Utils.showLoading(context);
|
|
// try {
|
|
// SwipeModel? swipeResponse = await dashBoardProvider.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) {
|
|
// Utils.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));
|
|
// Utils.hideLoading(context);
|
|
// showMDialog(
|
|
// context,
|
|
// backgroundColor: Colors.transparent,
|
|
// isDismissable: true,
|
|
// child: SuccessDialog(widget.isFromDashboard),
|
|
// );
|
|
// }
|
|
// } catch (ex) {
|
|
// Utils.hideLoading(context);
|
|
// // Utils.handleException(ex, context, null);
|
|
// }
|
|
// // Utils.showLoading(context);
|
|
// // try {
|
|
// // GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 2, nfcValue: nfcId ?? "", isGpsRequired: isNfcLocationEnabled, lat: lat, long: lng);
|
|
// // if (g?.messageStatus != 1) {
|
|
// // Utils.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);
|
|
// // Utils.hideLoading(context);
|
|
// // showMDialog(
|
|
// // context,
|
|
// // backgroundColor: Colors.transparent,
|
|
// // isDismissable: false,
|
|
// // child: SuccessDialog(widget.isFromDashboard),
|
|
// // );
|
|
// // }
|
|
// // } catch (ex) {
|
|
// // log(ex);
|
|
// // Utils.hideLoading(context);
|
|
// // // Utils.handleException(ex, context, (String msg) {
|
|
// // // Utils.confirmDialog(context, msg);
|
|
// // // });
|
|
// // }
|
|
// });
|
|
// }
|
|
// }
|
|
//
|
|
//
|
|
//
|
|
// void showMDialog(context, {Widget? child, Color? backgroundColor, bool isDismissable = true, bool isBusniessCard = false}) async {
|
|
// return showDialog(
|
|
// context: context,
|
|
// barrierDismissible: isDismissable,
|
|
// builder: (context) {
|
|
// return Dialog(
|
|
// shape: isBusniessCard
|
|
// ? const RoundedRectangleBorder(
|
|
// borderRadius: BorderRadius.all(
|
|
// Radius.circular(15.0),
|
|
// ),
|
|
// )
|
|
// : null,
|
|
// backgroundColor: backgroundColor,
|
|
// child: child,
|
|
// );
|
|
// },
|
|
// );
|
|
// }
|
|
// //
|
|
// // Future<bool> checkSession() async {
|
|
// // try {
|
|
// // Utils.showLoading(context);
|
|
// // await DashboardApiClient().getOpenMissingSwipes();
|
|
// // Utils.hideLoading(context);
|
|
// // return true;
|
|
// // } catch (ex) {
|
|
// // Utils.hideLoading(context);
|
|
// // Utils.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;
|
|
// // // }
|
|
// // // }
|
|
// // Utils.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);
|
|
// // Utils.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();
|
|
// // Utils.hideLoading(context);
|
|
// // Utils.handleException(ex, context, null);
|
|
// // }
|
|
// // } else {
|
|
// // if (AppState().isAuthenticated) {
|
|
// // Utils.hideLoading(context);
|
|
// // Utils.confirmDialog(context, "LocaleKeys.comeNearHMGWifi.tr()");
|
|
// // } else {
|
|
// // await closeWifiRequest();
|
|
// // }
|
|
// // }
|
|
// // }
|
|
//
|
|
// Future<bool> closeWifiRequest() async {
|
|
// if (Platform.isAndroid) {
|
|
// await WiFiForIoTPlugin.forceWifiUsage(false);
|
|
// }
|
|
// return await WiFiForIoTPlugin.disconnect();
|
|
// }
|
|
//
|
|
// Future<void> performQrCodeAttendance( {double ? latitude , double ?longitude}) async {
|
|
// DashBoardProvider dashBoardProvider = Provider.of<DashBoardProvider>(context,listen: false);
|
|
// var qrCodeValue = await Navigator.of(context).push(
|
|
// MaterialPageRoute(
|
|
// builder: (BuildContext context) => QrScannerDialog(),
|
|
// ),
|
|
// );
|
|
// if (qrCodeValue != null) {
|
|
// Utils.showLoading(context);
|
|
// try {
|
|
// final swipeModel = Swipe(
|
|
// swipeTypeValue: SwipeTypeEnum.QR.getIntFromSwipeTypeEnum(),
|
|
// value: qrCodeValue,
|
|
// latitude: latitude,
|
|
// longitude: longitude,
|
|
// );
|
|
// log('model i got to scan qr is ${swipeModel.toJson()}');
|
|
// final swipeResponse = await dashBoardProvider.makeSwipe(model: swipeModel);
|
|
// log('response of swipe is ${swipeResponse.toJson()}');
|
|
//
|
|
// bool status = await swipeResponse.data;
|
|
// Utils.hideLoading(context);
|
|
// if (swipeResponse.responseCode == 2) {
|
|
// showDialog(
|
|
// barrierDismissible: true,
|
|
// context: context,
|
|
// builder: (cxt) => ConfirmDialog(
|
|
// message: swipeResponse.message ?? "",
|
|
// onTap: () {
|
|
// Navigator.pop(context);
|
|
// },
|
|
// onCloseTap: () {},
|
|
// ),
|
|
// );
|
|
// } else {
|
|
// showMDialog(
|
|
// context,
|
|
// backgroundColor: Colors.transparent,
|
|
// isDismissable: true,
|
|
// child: SuccessDialog(widget.isFromDashboard),
|
|
// );
|
|
// }
|
|
// } catch (ex) {
|
|
// log('$ex');
|
|
// Utils.hideLoading(context);
|
|
// //this need to confirm where it comes..
|
|
// // Utils.handleException(ex, context, null);
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// void markFakeAttendance(dynamic sourceName, String lat, String long) async {
|
|
// Utils.showLoading(context);
|
|
// try {
|
|
// // await DashboardApiClient().markFakeLocation(sourceName: sourceName, lat: lat, long: long);
|
|
// Utils.hideLoading(context);
|
|
// Utils.confirmDialog(context, "LocaleKeys.fakeLocation.tr()");
|
|
// } catch (ex) {
|
|
// log('$ex');
|
|
// Utils.hideLoading(context);
|
|
// //Utils.handleException(ex, context, null);
|
|
// }
|
|
// }
|
|
//
|
|
// Widget attendanceMethod(String title, IconData iconData, bool isEnabled, VoidCallback onPress) => 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();
|
|
// },
|
|
// );
|
|
// }
|