|
|
|
@ -1,13 +1,11 @@
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
|
import 'package:geolocator/geolocator.dart';
|
|
|
|
|
import 'package:huawei_location/location/fused_location_provider_client.dart';
|
|
|
|
|
import 'package:huawei_location/location/location_request.dart';
|
|
|
|
|
import 'package:huawei_location/location/location_settings_request.dart';
|
|
|
|
|
import 'package:huawei_location/permission/permission_handler.dart';
|
|
|
|
|
import 'package:huawei_location/huawei_location.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/api/dashboard_api_client.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/app_state/app_state.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/colors.dart';
|
|
|
|
@ -21,7 +19,7 @@ import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/ui/dialogs/success_dialog.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/dialogs/dialogs.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/location/Location.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/location/Location.dart' as location;
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/nfc/nfc_reader_sheet.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/qr_scanner_dialog.dart';
|
|
|
|
|
import 'package:nfc_manager/nfc_manager.dart';
|
|
|
|
@ -75,26 +73,61 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void checkHuaweiLocationPermission(String attendanceType) async {
|
|
|
|
|
PermissionHandler permissionHandler = PermissionHandler();
|
|
|
|
|
|
|
|
|
|
if (await permissionHandler.hasLocationPermission()) {
|
|
|
|
|
getHuaweiCurrentLocation(attendanceType);
|
|
|
|
|
} else {
|
|
|
|
|
bool has = await requestPermissions();
|
|
|
|
|
if (has) {
|
|
|
|
|
getHuaweiCurrentLocation(attendanceType);
|
|
|
|
|
// 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 give location permission to mark attendance",
|
|
|
|
|
onTap: () {
|
|
|
|
|
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 {
|
|
|
|
@ -134,11 +167,11 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
if (AppState().getIsHuawei) {
|
|
|
|
|
checkHuaweiLocationPermission("NFC");
|
|
|
|
|
} else {
|
|
|
|
|
Location.isEnabled((bool isEnabled) {
|
|
|
|
|
location.Location.isEnabled((bool isEnabled) {
|
|
|
|
|
if (isEnabled) {
|
|
|
|
|
Location.havePermission((bool permission) {
|
|
|
|
|
location.Location.havePermission((bool permission) {
|
|
|
|
|
if (permission) {
|
|
|
|
|
Location.getCurrentLocation(
|
|
|
|
|
location.Location.getCurrentLocation(
|
|
|
|
|
(Position position, bool isMocked) {
|
|
|
|
|
if (isMocked) {
|
|
|
|
|
markFakeAttendance("NFC", position.latitude.toString() ?? "", position.longitude.toString() ?? "");
|
|
|
|
@ -181,11 +214,11 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
if (AppState().getIsHuawei) {
|
|
|
|
|
checkHuaweiLocationPermission("WIFI");
|
|
|
|
|
} else {
|
|
|
|
|
Location.isEnabled((bool isEnabled) {
|
|
|
|
|
location.Location.isEnabled((bool isEnabled) {
|
|
|
|
|
if (isEnabled) {
|
|
|
|
|
Location.havePermission((bool permission) {
|
|
|
|
|
location.Location.havePermission((bool permission) {
|
|
|
|
|
if (permission) {
|
|
|
|
|
Location.getCurrentLocation(
|
|
|
|
|
location.Location.getCurrentLocation(
|
|
|
|
|
(Position position, bool isMocked) {
|
|
|
|
|
if (isMocked) {
|
|
|
|
|
markFakeAttendance("WIFI", position.latitude.toString() ?? "", position.longitude.toString() ?? "");
|
|
|
|
@ -228,11 +261,11 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
if (AppState().getIsHuawei) {
|
|
|
|
|
checkHuaweiLocationPermission("QR");
|
|
|
|
|
} else {
|
|
|
|
|
Location.isEnabled((bool isEnabled) {
|
|
|
|
|
location.Location.isEnabled((bool isEnabled) {
|
|
|
|
|
if (isEnabled) {
|
|
|
|
|
Location.havePermission((bool permission) {
|
|
|
|
|
location.Location.havePermission((bool permission) {
|
|
|
|
|
if (permission) {
|
|
|
|
|
Location.getCurrentLocation(
|
|
|
|
|
location.Location.getCurrentLocation(
|
|
|
|
|
(Position position, bool isMocked) {
|
|
|
|
|
if (isMocked) {
|
|
|
|
|
markFakeAttendance("QR", position.latitude.toString() ?? "", position.longitude.toString() ?? "");
|
|
|
|
@ -277,49 +310,70 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void getHuaweiCurrentLocation(String attendanceType) {
|
|
|
|
|
void getHuaweiCurrentLocation(String attendanceType) async {
|
|
|
|
|
try {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
FusedLocationProviderClient locationService = FusedLocationProviderClient();
|
|
|
|
|
LocationRequest locationRequest = LocationRequest();
|
|
|
|
|
locationRequest.priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
|
|
|
|
|
locationRequest.interval = 1000;
|
|
|
|
|
locationRequest.interval = 500;
|
|
|
|
|
List<LocationRequest> locationRequestList = <LocationRequest>[locationRequest];
|
|
|
|
|
LocationSettingsRequest locationSettingsRequest = LocationSettingsRequest(requests: locationRequestList);
|
|
|
|
|
|
|
|
|
|
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() ?? "");
|
|
|
|
|
}
|
|
|
|
|
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") {
|
|
|
|
|
performQrCodeAttendance(widget.model, lat: location.latitude.toString() ?? "", lng: location.longitude.toString() ?? "");
|
|
|
|
|
}
|
|
|
|
|
}).catchError((error) {
|
|
|
|
|
print("HUAWEI LOCATION getLastLocation ERROR!!!!!");
|
|
|
|
|
print(error);
|
|
|
|
|
});
|
|
|
|
|
}).catchError((error) {
|
|
|
|
|
print("HUAWEI LOCATION checkLocationSettings ERROR!!!!!");
|
|
|
|
|
print(error);
|
|
|
|
|
if (error.code == "LOCATION_SETTINGS_NOT_AVAILABLE") {
|
|
|
|
|
// Location service not enabled.
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if (attendanceType == "WIFI") {
|
|
|
|
|
performWifiAttendance(widget.model, lat: location.latitude.toString() ?? "", lng: location.longitude.toString() ?? "");
|
|
|
|
|
}
|
|
|
|
|
if (attendanceType == "NFC") {
|
|
|
|
|
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) {
|
|
|
|
|
// print("HUAWEI LOCATION getLastLocation ERROR!!!!!");
|
|
|
|
|
// print(error);
|
|
|
|
|
// });
|
|
|
|
|
// }).catchError((error) {
|
|
|
|
|
// print("HUAWEI LOCATION checkLocationSettings ERROR!!!!!");
|
|
|
|
|
// print(error);
|
|
|
|
|
// if (error.code == "LOCATION_SETTINGS_NOT_AVAILABLE") {
|
|
|
|
|
// // Location service not enabled.
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
print("HUAWEI LOCATION ERROR!!!!!");
|
|
|
|
|
print(error);
|
|
|
|
|