|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:developer';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:geolocator/geolocator.dart';
|
|
|
|
|
import 'package:google_api_availability/google_api_availability.dart';
|
|
|
|
|
@ -35,9 +36,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
|
|
|
|
|
static bool get isLoading => _isLoadingVisible;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void markFakeAttendance(dynamic sourceName, String lat, String long, @required BuildContext context) async {
|
|
|
|
|
void markFakeAttendance(dynamic sourceName, String lat, String long, @required BuildContext context) async {
|
|
|
|
|
showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
hideLoading(navigatorKey.currentState.overlay.context);
|
|
|
|
|
@ -49,9 +48,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void showLoading(BuildContext context) {
|
|
|
|
|
void showLoading(BuildContext context) {
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
_isLoadingVisible = true;
|
|
|
|
|
showDialog(
|
|
|
|
|
@ -65,7 +62,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void hideLoading(BuildContext context) {
|
|
|
|
|
void hideLoading(BuildContext context) {
|
|
|
|
|
if (_isLoadingVisible) {
|
|
|
|
|
_isLoadingVisible = false;
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
@ -78,24 +75,21 @@ class SwipeGeneralUtils {
|
|
|
|
|
return prefs.getString(key) ?? "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void confirmDialog(cxt, String message, {VoidCallback onTap}) {
|
|
|
|
|
void confirmDialog(cxt, String message, {VoidCallback onTap}) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: cxt,
|
|
|
|
|
builder: (BuildContext cxt) => ConfirmDialog(message: message, onTap: onTap),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void showErrorDialog({String message, @required BuildContext context}) {
|
|
|
|
|
void showErrorDialog({String message, @required BuildContext context}) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) => ConfirmDialog(message: message, title: 'Error', onTap: () => Navigator.pop(context)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void showMDialog(context, {Widget child, Color backgroundColor, bool isDismissable = true, bool isBusniessCard = false}) async {
|
|
|
|
|
void showMDialog(context, {Widget child, Color backgroundColor, bool isDismissable = true, bool isBusniessCard = false}) async {
|
|
|
|
|
return showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
barrierDismissible: isDismissable,
|
|
|
|
|
@ -115,7 +109,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget attendanceTypeCard(String title, String icon, bool isEnabled, VoidCallback onPress, BuildContext context) {
|
|
|
|
|
Widget attendanceTypeCard(String title, String icon, bool isEnabled, VoidCallback onPress, BuildContext context) {
|
|
|
|
|
return Container(
|
|
|
|
|
padding: const EdgeInsets.all(12),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
@ -140,7 +134,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//huawei permission part....
|
|
|
|
|
void getHuaweiCurrentLocation({SwipeTypeEnum attendanceType, BuildContext context}) async {
|
|
|
|
|
void getHuaweiCurrentLocation({SwipeTypeEnum attendanceType, BuildContext context}) async {
|
|
|
|
|
try {
|
|
|
|
|
showLoading(context);
|
|
|
|
|
FusedLocationProviderClient locationService = FusedLocationProviderClient()..initFusedLocationService();
|
|
|
|
|
@ -156,8 +150,8 @@ class SwipeGeneralUtils {
|
|
|
|
|
_streamSubscription = locationService.onLocationData.listen(
|
|
|
|
|
(Location location) async {
|
|
|
|
|
hideLoading(context);
|
|
|
|
|
await locationService.removeLocationUpdates(requestCode);
|
|
|
|
|
handleSwipeOperation(swipeType: attendanceType, context: context,lat:location.latitude ,long:location.longitude );
|
|
|
|
|
await locationService.removeLocationUpdates(requestCode); // todo #test on release mode.
|
|
|
|
|
handleSwipeOperation(swipeType: attendanceType, context: context, lat: location.latitude, long: location.longitude);
|
|
|
|
|
requestCode = 0;
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
@ -169,14 +163,14 @@ class SwipeGeneralUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<bool> requestPermissions() async {
|
|
|
|
|
Future<bool> requestPermissions() async {
|
|
|
|
|
var result = await [
|
|
|
|
|
Permission.location,
|
|
|
|
|
].request();
|
|
|
|
|
return (result[Permission.location] == PermissionStatus.granted || result[Permission.locationAlways] == PermissionStatus.granted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void checkHuaweiLocationPermission({SwipeTypeEnum attendanceType, BuildContext context}) async {
|
|
|
|
|
void checkHuaweiLocationPermission({SwipeTypeEnum attendanceType, BuildContext context}) async {
|
|
|
|
|
// Permission_Handler permissionHandler = PermissionHandler();
|
|
|
|
|
LocationUtilities.isEnabled((bool isEnabled) async {
|
|
|
|
|
if (isEnabled) {
|
|
|
|
|
@ -234,7 +228,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleSwipeOperation({@required SwipeTypeEnum swipeType, double lat, double long, BuildContext context}) {
|
|
|
|
|
void handleSwipeOperation({@required SwipeTypeEnum swipeType, double lat, double long, BuildContext context}) {
|
|
|
|
|
switch (swipeType) {
|
|
|
|
|
case SwipeTypeEnum.NFC:
|
|
|
|
|
handleNfcAttendance(latitude: lat, longitude: long, context: context);
|
|
|
|
|
@ -243,16 +237,16 @@ class SwipeGeneralUtils {
|
|
|
|
|
performQrCodeAttendance(latitude: lat, longitude: long, context: context);
|
|
|
|
|
return;
|
|
|
|
|
case SwipeTypeEnum.Wifi:
|
|
|
|
|
//TODO need to implement.
|
|
|
|
|
performQrCodeAttendance(latitude: lat, longitude: long, context: context);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String formatTimeOnly(DateTime dateTime) {
|
|
|
|
|
String formatTimeOnly(DateTime dateTime) {
|
|
|
|
|
return DateFormat.Hms().format(dateTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> performQrCodeAttendance({double latitude, double longitude, BuildContext context}) async {
|
|
|
|
|
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(
|
|
|
|
|
@ -270,7 +264,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
longitude: longitude,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await userProvider.makeSwipe(model: swipeModel).then((swipeResponse) {
|
|
|
|
|
await userProvider.makeSwipe(model: swipeModel).then((swipeResponse) {
|
|
|
|
|
if (swipeResponse.isSuccess) {
|
|
|
|
|
hideLoading(context);
|
|
|
|
|
Navigator.pushNamed(context, SwipeSuccessView.routeName);
|
|
|
|
|
@ -289,8 +283,6 @@ class SwipeGeneralUtils {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
log('$ex');
|
|
|
|
|
hideLoading(context);
|
|
|
|
|
@ -300,7 +292,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> handleNfcAttendance({double latitude = 0, double longitude = 0, BuildContext context}) async {
|
|
|
|
|
Future<void> handleNfcAttendance({double latitude = 0, double longitude = 0, BuildContext context}) async {
|
|
|
|
|
// UserProvider _userProvider = Provider.of<UserProvider>(context,listen:false);
|
|
|
|
|
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
@ -314,7 +306,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _processNfcAttendance(
|
|
|
|
|
Future<void> _processNfcAttendance(
|
|
|
|
|
String nfcId,
|
|
|
|
|
double latitude,
|
|
|
|
|
double longitude,
|
|
|
|
|
@ -322,18 +314,11 @@ class SwipeGeneralUtils {
|
|
|
|
|
) async {
|
|
|
|
|
showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
final swipeModel = Swipe(
|
|
|
|
|
swipeTypeValue: SwipeTypeEnum.NFC.getIntFromSwipeTypeEnum(),
|
|
|
|
|
value: nfcId,
|
|
|
|
|
latitude: latitude,
|
|
|
|
|
longitude: longitude,
|
|
|
|
|
);
|
|
|
|
|
final swipeModel = Swipe(swipeTypeValue: SwipeTypeEnum.NFC.getIntFromSwipeTypeEnum(), value: nfcId, latitude: latitude, longitude: longitude);
|
|
|
|
|
UserProvider userProvider = Provider.of<UserProvider>(context, listen: false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final swipeResponse = await userProvider.makeSwipe(model: swipeModel);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (swipeResponse.isSuccess) {
|
|
|
|
|
hideLoading(context);
|
|
|
|
|
Navigator.pushNamed(context, SwipeSuccessView.routeName);
|
|
|
|
|
@ -346,7 +331,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleSwipe({SwipeTypeEnum swipeType, @required bool isEnable, @required BuildContext context}) async {
|
|
|
|
|
void handleSwipe({SwipeTypeEnum swipeType, @required bool isEnable, @required BuildContext context}) async {
|
|
|
|
|
if (!(await isGoogleServicesAvailable())) {
|
|
|
|
|
checkHuaweiLocationPermission(attendanceType: swipeType, context: context);
|
|
|
|
|
} else {
|
|
|
|
|
@ -390,7 +375,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void showInfoDialog({@required String message, VoidCallback onTap}) {
|
|
|
|
|
void showInfoDialog({@required String message, VoidCallback onTap}) {
|
|
|
|
|
showDialog(
|
|
|
|
|
context: navigatorKey.currentState.overlay.context,
|
|
|
|
|
builder: (BuildContext cxt) => ConfirmDialog(
|
|
|
|
|
@ -403,7 +388,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Widget> availableAttendanceMethodList({@required BuildContext context, @required UserProvider userProvider, @required bool isNfcSupported}) {
|
|
|
|
|
List<Widget> availableAttendanceMethodList({@required BuildContext context, @required UserProvider userProvider, @required bool isNfcSupported}) {
|
|
|
|
|
List<Widget> availableMethods = [];
|
|
|
|
|
if (userProvider.user.enableNFC) {
|
|
|
|
|
availableMethods.add(attendanceTypeCard(SwipeTypeEnum.NFC.name, 'nfc_icon', isNfcSupported, () {
|
|
|
|
|
@ -417,6 +402,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
handleSwipe(swipeType: SwipeTypeEnum.QR, isEnable: userProvider.user.enableQR, context: navigatorKey.currentState.overlay.context);
|
|
|
|
|
}, context));
|
|
|
|
|
}
|
|
|
|
|
userProvider.user.enableWifi= true;
|
|
|
|
|
if (userProvider.user.enableWifi) {
|
|
|
|
|
availableMethods.add(attendanceTypeCard(SwipeTypeEnum.Wifi.name, 'wifi_icon', userProvider.user.enableWifi, () {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
@ -426,7 +412,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
return availableMethods;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void showSwipeTypeBottomSheetSheet({@required bool isNfcSupported}) {
|
|
|
|
|
void showSwipeTypeBottomSheetSheet({@required bool isNfcSupported}) {
|
|
|
|
|
BuildContext context = navigatorKey.currentState.overlay.context;
|
|
|
|
|
UserProvider _userProvider = Provider.of<UserProvider>(context, listen: false);
|
|
|
|
|
|
|
|
|
|
@ -457,7 +443,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void readNFc({Function(String) onRead}) {
|
|
|
|
|
void readNFc({Function(String) onRead}) {
|
|
|
|
|
NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async {
|
|
|
|
|
MifareUltralight f;
|
|
|
|
|
if (Platform.isAndroid) {
|
|
|
|
|
@ -474,7 +460,7 @@ class SwipeGeneralUtils {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//HUAWEI DECISION MAKING
|
|
|
|
|
Future<bool> isGoogleServicesAvailable() async {
|
|
|
|
|
Future<bool> isGoogleServicesAvailable() async {
|
|
|
|
|
GooglePlayServicesAvailability availability = await GoogleApiAvailability.instance.checkGooglePlayServicesAvailability();
|
|
|
|
|
String status = availability.toString().split('.').last;
|
|
|
|
|
if (status == "success") {
|
|
|
|
|
@ -482,6 +468,4 @@ class SwipeGeneralUtils {
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|