|
|
|
@ -152,35 +152,86 @@ class SwipeGeneralUtils {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//huawei permission part....
|
|
|
|
//huawei permission part....
|
|
|
|
void getHuaweiCurrentLocation({SwipeTypeEnum? attendanceType, required BuildContext context}) async {
|
|
|
|
Future<void> getHuaweiCurrentLocation({
|
|
|
|
|
|
|
|
SwipeTypeEnum? attendanceType,
|
|
|
|
|
|
|
|
required BuildContext context,
|
|
|
|
|
|
|
|
}) async {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
showLoading(context);
|
|
|
|
showLoading(context);
|
|
|
|
FusedLocationProviderClient locationService = FusedLocationProviderClient()..initFusedLocationService();
|
|
|
|
|
|
|
|
LocationRequest locationRequest = LocationRequest();
|
|
|
|
final locationService = FusedLocationProviderClient()..initFusedLocationService();
|
|
|
|
locationRequest.priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
|
|
|
|
final locationRequest = LocationRequest()
|
|
|
|
locationRequest.interval = 500;
|
|
|
|
..priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY
|
|
|
|
List<LocationRequest> locationRequestList = <LocationRequest>[locationRequest];
|
|
|
|
..interval = 500;
|
|
|
|
LocationSettingsRequest locationSettingsRequest = LocationSettingsRequest(requests: locationRequestList);
|
|
|
|
|
|
|
|
|
|
|
|
final requestCode = await locationService.requestLocationUpdates(locationRequest) ?? 0;
|
|
|
|
late StreamSubscription<Location> _streamSubscription;
|
|
|
|
|
|
|
|
int requestCode = (await (locationService.requestLocationUpdates(locationRequest)))!;
|
|
|
|
final streamSubscription = locationService.onLocationData?.listen(
|
|
|
|
_streamSubscription = locationService.onLocationData!.listen(
|
|
|
|
(location) async {
|
|
|
|
(Location location) async {
|
|
|
|
if (location == null) {
|
|
|
|
|
|
|
|
hideLoading(context);
|
|
|
|
|
|
|
|
debugPrint("Location data is null");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
hideLoading(context);
|
|
|
|
hideLoading(context);
|
|
|
|
await locationService.removeLocationUpdates(requestCode);
|
|
|
|
await locationService.removeLocationUpdates(requestCode);
|
|
|
|
handleSwipeOperation(swipeType: attendanceType!, context: context, lat: location.latitude ?? 0, long: location.longitude ?? 0);
|
|
|
|
handleSwipeOperation(
|
|
|
|
requestCode = 0;
|
|
|
|
swipeType: attendanceType!,
|
|
|
|
_streamSubscription.cancel();
|
|
|
|
context: context,
|
|
|
|
|
|
|
|
lat: location.latitude ?? 0,
|
|
|
|
|
|
|
|
long: location.longitude ?? 0,
|
|
|
|
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
streamSubscription?.onDone(() {
|
|
|
|
|
|
|
|
streamSubscription.cancel();
|
|
|
|
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
log("HUAWEI LOCATION ERROR!!!!!");
|
|
|
|
debugPrint("HUAWEI LOCATION ERROR!!!!!");
|
|
|
|
log('$error');
|
|
|
|
debugPrint('$error');
|
|
|
|
hideLoading(context);
|
|
|
|
hideLoading(context);
|
|
|
|
// handleException(error, context, null);
|
|
|
|
showDialog(
|
|
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
|
|
builder: (BuildContext cxt) => ConfirmDialog(
|
|
|
|
|
|
|
|
message: "Unable to fetch location. Please try again.",
|
|
|
|
|
|
|
|
onTap: () {
|
|
|
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// void getHuaweiCurrentLocation({SwipeTypeEnum? attendanceType, required BuildContext context}) async {
|
|
|
|
|
|
|
|
// try {
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
|
|
|
|
// hideLoading(context);
|
|
|
|
|
|
|
|
// await locationService.removeLocationUpdates(requestCode);
|
|
|
|
|
|
|
|
// handleSwipeOperation(swipeType: attendanceType!, context: context, lat: location.latitude ?? 0, long: location.longitude ?? 0);
|
|
|
|
|
|
|
|
// requestCode = 0;
|
|
|
|
|
|
|
|
// _streamSubscription.cancel();
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// );
|
|
|
|
|
|
|
|
// } catch (error) {
|
|
|
|
|
|
|
|
// log("HUAWEI LOCATION ERROR!!!!!");
|
|
|
|
|
|
|
|
// log('$error');
|
|
|
|
|
|
|
|
// hideLoading(context);
|
|
|
|
|
|
|
|
// // handleException(error, context, null);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
Future<bool> requestPermissions() async {
|
|
|
|
Future<bool> requestPermissions() async {
|
|
|
|
var result = await [
|
|
|
|
var result = await [
|
|
|
|
Permission.location,
|
|
|
|
Permission.location,
|
|
|
|
@ -188,31 +239,71 @@ class SwipeGeneralUtils {
|
|
|
|
return (result[Permission.location] == PermissionStatus.granted || result[Permission.locationAlways] == PermissionStatus.granted);
|
|
|
|
return (result[Permission.location] == PermissionStatus.granted || result[Permission.locationAlways] == PermissionStatus.granted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void checkHuaweiLocationPermission({required SwipeTypeEnum attendanceType, required BuildContext context}) async {
|
|
|
|
//TODO delete older code after confirm the new one is working fine in huawei devices
|
|
|
|
// Permission_Handler permissionHandler = PermissionHandler();
|
|
|
|
// void checkHuaweiLocationPermission({required SwipeTypeEnum attendanceType, required BuildContext context}) async {
|
|
|
|
LocationUtilities.isEnabled((bool isEnabled) async {
|
|
|
|
// // Permission_Handler permissionHandler = PermissionHandler();
|
|
|
|
if (isEnabled) {
|
|
|
|
// LocationUtilities.isEnabled((bool isEnabled) async {
|
|
|
|
LocationUtilities.havePermission((bool permission) async {
|
|
|
|
// if (isEnabled) {
|
|
|
|
if (permission) {
|
|
|
|
// LocationUtilities.havePermission((bool permission) async {
|
|
|
|
getHuaweiCurrentLocation(attendanceType: attendanceType, context: context);
|
|
|
|
// if (permission) {
|
|
|
|
} else {
|
|
|
|
// getHuaweiCurrentLocation(attendanceType: attendanceType, context: context);
|
|
|
|
bool has = await requestPermissions();
|
|
|
|
// } else {
|
|
|
|
if (has) {
|
|
|
|
// bool has = await requestPermissions();
|
|
|
|
getHuaweiCurrentLocation(attendanceType: attendanceType, context: context);
|
|
|
|
// if (has) {
|
|
|
|
} else {
|
|
|
|
// getHuaweiCurrentLocation(attendanceType: attendanceType, context: context);
|
|
|
|
showDialog(
|
|
|
|
// } else {
|
|
|
|
context: context,
|
|
|
|
// showDialog(
|
|
|
|
builder: (BuildContext cxt) => ConfirmDialog(
|
|
|
|
// context: context,
|
|
|
|
message: "You need to give location permission to mark attendance",
|
|
|
|
// builder: (BuildContext cxt) => ConfirmDialog(
|
|
|
|
onTap: () {
|
|
|
|
// message: "You need to give location permission to mark attendance",
|
|
|
|
Navigator.pop(context);
|
|
|
|
// onTap: () {
|
|
|
|
},
|
|
|
|
// Navigator.pop(context);
|
|
|
|
),
|
|
|
|
// },
|
|
|
|
);
|
|
|
|
// ),
|
|
|
|
}
|
|
|
|
// );
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
});
|
|
|
|
// }
|
|
|
|
} else {
|
|
|
|
// });
|
|
|
|
|
|
|
|
// } 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<void> checkHuaweiLocationPermission({
|
|
|
|
|
|
|
|
required SwipeTypeEnum attendanceType,
|
|
|
|
|
|
|
|
required BuildContext context,
|
|
|
|
|
|
|
|
}) async {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
final isEnabled = await LocationUtilities.isEnabledAsync();
|
|
|
|
|
|
|
|
if (!isEnabled) {
|
|
|
|
showDialog(
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext cxt) => ConfirmDialog(
|
|
|
|
builder: (BuildContext cxt) => ConfirmDialog(
|
|
|
|
@ -223,27 +314,40 @@ class SwipeGeneralUtils {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (await permissionHandler.hasLocationPermission()) {
|
|
|
|
final hasPermission = await LocationUtilities.havePermissionAsync();
|
|
|
|
// getHuaweiCurrentLocation(attendanceType);
|
|
|
|
if (!hasPermission) {
|
|
|
|
// } else {
|
|
|
|
final granted = await requestPermissions();
|
|
|
|
// bool has = await requestPermissions();
|
|
|
|
if (!granted) {
|
|
|
|
// if (has) {
|
|
|
|
showDialog(
|
|
|
|
// getHuaweiCurrentLocation(attendanceType);
|
|
|
|
context: context,
|
|
|
|
// } else {
|
|
|
|
builder: (BuildContext cxt) => ConfirmDialog(
|
|
|
|
// showDialog(
|
|
|
|
message: "You need to give location permission to mark attendance",
|
|
|
|
// context: context,
|
|
|
|
onTap: () {
|
|
|
|
// builder: (BuildContext cxt) => ConfirmDialog(
|
|
|
|
Navigator.pop(context);
|
|
|
|
// message: "You need to give location permission to mark attendance",
|
|
|
|
},
|
|
|
|
// onTap: () {
|
|
|
|
),
|
|
|
|
// Navigator.pop(context);
|
|
|
|
);
|
|
|
|
// },
|
|
|
|
return;
|
|
|
|
// ),
|
|
|
|
}
|
|
|
|
// );
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
// Proceed to get location
|
|
|
|
|
|
|
|
await getHuaweiCurrentLocation(attendanceType: attendanceType, context: context);
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
debugPrint("Error in checkHuaweiLocationPermission: $error");
|
|
|
|
|
|
|
|
showDialog(
|
|
|
|
|
|
|
|
context: context,
|
|
|
|
|
|
|
|
builder: (BuildContext cxt) => ConfirmDialog(
|
|
|
|
|
|
|
|
message: "An unexpected error occurred. Please try again.",
|
|
|
|
|
|
|
|
onTap: () {
|
|
|
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void handleSwipeOperation({required SwipeTypeEnum swipeType, required double lat, required double long, required BuildContext context}) {
|
|
|
|
void handleSwipeOperation({required SwipeTypeEnum swipeType, required double lat, required double long, required BuildContext context}) {
|
|
|
|
@ -362,7 +466,6 @@ class SwipeGeneralUtils {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Check if location is enabled
|
|
|
|
|
|
|
|
final isEnabled = await LocationUtilities.isEnabledAsync();
|
|
|
|
final isEnabled = await LocationUtilities.isEnabledAsync();
|
|
|
|
if (!isEnabled) {
|
|
|
|
if (!isEnabled) {
|
|
|
|
showInfoDialog(
|
|
|
|
showInfoDialog(
|
|
|
|
@ -371,8 +474,6 @@ class SwipeGeneralUtils {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Check permission
|
|
|
|
|
|
|
|
final hasPermission = await LocationUtilities.havePermissionAsync();
|
|
|
|
final hasPermission = await LocationUtilities.havePermissionAsync();
|
|
|
|
if (!hasPermission) {
|
|
|
|
if (!hasPermission) {
|
|
|
|
showInfoDialog(
|
|
|
|
showInfoDialog(
|
|
|
|
@ -381,11 +482,7 @@ class SwipeGeneralUtils {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Show loader
|
|
|
|
|
|
|
|
showLoading(context);
|
|
|
|
showLoading(context);
|
|
|
|
|
|
|
|
|
|
|
|
// Get location
|
|
|
|
|
|
|
|
await LocationUtilities.getCurrentLocation(
|
|
|
|
await LocationUtilities.getCurrentLocation(
|
|
|
|
(Position position, bool isMocked) {
|
|
|
|
(Position position, bool isMocked) {
|
|
|
|
hideLoading(context);
|
|
|
|
hideLoading(context);
|
|
|
|
@ -426,7 +523,7 @@ class SwipeGeneralUtils {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//older code..
|
|
|
|
//TODO delete older code..
|
|
|
|
// void handleSwipe({required SwipeTypeEnum swipeType, required bool isEnable, required BuildContext context}) async {
|
|
|
|
// void handleSwipe({required SwipeTypeEnum swipeType, required bool isEnable, required BuildContext context}) async {
|
|
|
|
// if (Platform.isAndroid && !(await isGoogleServicesAvailable())) {
|
|
|
|
// if (Platform.isAndroid && !(await isGoogleServicesAvailable())) {
|
|
|
|
// checkHuaweiLocationPermission(attendanceType: swipeType, context: context);
|
|
|
|
// checkHuaweiLocationPermission(attendanceType: swipeType, context: context);
|
|
|
|
|