Attendance fixes

merge-requests/166/head
haroon amjad 3 years ago
parent a142a5e8df
commit 20109cbe9e

@ -52,7 +52,7 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "hmg.cloudSolutions.mohem"
minSdkVersion 25
minSdkVersion 28
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName

@ -31,7 +31,7 @@ class ChatApiClient {
"employeeNumber": AppState().memberInformationList!.eMPLOYEENUMBER.toString(),
"password": "FxIu26rWIKoF8n6mpbOmAjDLphzFGmpG",
"isMobile": true,
"deviceToken": AppState().getDeviceToken,
"deviceToken":AppState().getIsHuawei ? AppState().getHuaweiPushToken : AppState().getDeviceToken,
"isHuaweiDevice": AppState().getIsHuawei,
},
);

@ -4,6 +4,9 @@ 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: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';
@ -39,6 +42,8 @@ class MarkAttendanceWidget extends StatefulWidget {
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();
@ -95,13 +100,17 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
// if (isNfcEnabled)
attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, () {
if (isNfcLocationEnabled) {
Location.getCurrentLocation((Position position, bool isMocked) {
if (isMocked) {
markFakeAttendance("NFC", position.latitude.toString() ?? "", position.longitude.toString() ?? "");
} else {
performNfcAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? "");
}
}, context);
if (AppState().getIsHuawei) {
getHuaweiCurrentLocation("NFC");
} else {
Location.getCurrentLocation((Position position, bool isMocked) {
if (isMocked) {
markFakeAttendance("NFC", position.latitude.toString() ?? "", position.longitude.toString() ?? "");
} else {
performNfcAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? "");
}
}, context);
}
} else {
performNfcAttendance(widget.model);
}
@ -109,13 +118,17 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
if (isWifiEnabled)
attendanceMethod("Wifi", "assets/images/wufu.svg", isWifiEnabled, () {
if (isWifiLocationEnabled) {
Location.getCurrentLocation((Position position, bool isMocked) {
if (isMocked) {
markFakeAttendance("WIFI", position.latitude.toString() ?? "", position.longitude.toString() ?? "");
} else {
performWifiAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? "");
}
}, context);
if (AppState().getIsHuawei) {
getHuaweiCurrentLocation("WIFI");
} else {
Location.getCurrentLocation((Position position, bool isMocked) {
if (isMocked) {
markFakeAttendance("WIFI", position.latitude.toString() ?? "", position.longitude.toString() ?? "");
} else {
performWifiAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? "");
}
}, context);
}
} else {
performWifiAttendance(widget.model);
}
@ -124,13 +137,17 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
if (isQrEnabled)
attendanceMethod("QR", "assets/images/ic_qr.svg", isQrEnabled, () async {
if (isQrLocationEnabled) {
Location.getCurrentLocation((Position position, bool isMocked) {
if (isMocked) {
markFakeAttendance("QR", position.latitude.toString() ?? "", position.longitude.toString() ?? "");
} else {
performQrCodeAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? "");
}
}, context);
if (AppState().getIsHuawei) {
getHuaweiCurrentLocation("QR");
} else {
Location.getCurrentLocation((Position position, bool isMocked) {
if (isMocked) {
markFakeAttendance("QR", position.latitude.toString() ?? "", position.longitude.toString() ?? "");
} else {
performQrCodeAttendance(widget.model, lat: position.latitude.toString() ?? "", lng: position.longitude.toString() ?? "");
}
}, context);
}
} else {
performQrCodeAttendance(widget.model);
}
@ -143,6 +160,33 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
);
}
void getHuaweiCurrentLocation(String attendanceType) {
FusedLocationProviderClient locationService = FusedLocationProviderClient();
LocationRequest locationRequest = LocationRequest();
locationRequest.priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
locationRequest.interval = 1000;
List<LocationRequest> locationRequestList = <LocationRequest>[locationRequest];
LocationSettingsRequest locationSettingsRequest = LocationSettingsRequest(requests: locationRequestList);
locationService.checkLocationSettings(locationSettingsRequest).then((settings) async {
await locationService.getLastLocation().then((value) {
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) {
if (error.code == "LOCATION_SETTINGS_NOT_AVAILABLE") {
// Location service not enabled.
}
});
}
Future<void> performNfcAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async {
if (Platform.isIOS) {
Utils.readNFc(onRead: (String nfcId) async {
@ -252,12 +296,26 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
bool status = await model.fetchAttendanceTracking(context);
Utils.hideLoading(context);
await closeWifiRequest();
showMDialog(
context,
backgroundColor: Colors.transparent,
isDismissable: false,
child: SuccessDialog(widget.isFromDashboard),
);
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);
@ -292,12 +350,26 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 1, isGpsRequired: isQrLocationEnabled, lat: lat, long: lng, QRValue: qrCodeValue);
bool status = await model.fetchAttendanceTracking(context);
Utils.hideLoading(context);
showMDialog(
context,
backgroundColor: Colors.transparent,
isDismissable: true,
child: SuccessDialog(widget.isFromDashboard),
);
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: true,
child: SuccessDialog(widget.isFromDashboard),
);
}
} catch (ex) {
print(ex);
Utils.hideLoading(context);

@ -68,6 +68,8 @@ class _QrScannerDialogState extends State<QrScannerDialog> {
}
});
});
controller.pauseCamera();
controller.resumeCamera();
}
@override

@ -64,7 +64,7 @@ dependencies:
wifi_iot: ^0.3.18
flutter_html: ^3.0.0-alpha.6
# flutter_barcode_scanner: ^2.0.0
qr_code_scanner: ^1.0.0
qr_code_scanner: ^1.0.1
# qr_flutter: ^4.0.0
url_launcher: ^6.0.15
share: 2.0.4

Loading…
Cancel
Save