|
|
|
|
@ -33,7 +33,7 @@ class TodayAttendanceScreen extends StatefulWidget {
|
|
|
|
|
class _TodayAttendanceScreenState extends State<TodayAttendanceScreen> {
|
|
|
|
|
ValueNotifier<dynamic> result = ValueNotifier(null);
|
|
|
|
|
late DashboardProviderModel data;
|
|
|
|
|
bool isNfcEnabled = false, isNfcLocationEnabled = false, isQrEnabled = false, isQrLocationEnabled = false, isWifiEnabled = false, isWifiLocationEnabled = false;
|
|
|
|
|
bool isNfcEnabled = true, isNfcLocationEnabled = false, isQrEnabled = false, isQrLocationEnabled = false, isWifiEnabled = false, isWifiLocationEnabled = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
@ -42,19 +42,19 @@ class _TodayAttendanceScreenState extends State<TodayAttendanceScreen> {
|
|
|
|
|
data = Provider.of<DashboardProviderModel>(context, listen: false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkAttendanceAvailablity() async {
|
|
|
|
|
void checkAttendanceAvailablity() async {
|
|
|
|
|
bool isAvailable = await NfcManager.instance.isAvailable();
|
|
|
|
|
setState(() {
|
|
|
|
|
AppState().privilegeListModel!.forEach((element) {
|
|
|
|
|
// Check availability
|
|
|
|
|
if (isAvailable) if (element.serviceName == "enableNFC") {
|
|
|
|
|
// if (element.previlege ?? false)
|
|
|
|
|
isNfcEnabled = true;
|
|
|
|
|
print(element.serviceName.toString() + " " + element.previlege.toString()); // Check availability
|
|
|
|
|
|
|
|
|
|
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 == "enableLocatoinNFC") {
|
|
|
|
|
} else if (element.serviceName!.trim() == "enableLocationNFC") {
|
|
|
|
|
if (element.previlege ?? false) isNfcLocationEnabled = true;
|
|
|
|
|
} else if (element.serviceName == "enableLocationQR") {
|
|
|
|
|
if (element.previlege ?? false) isQrLocationEnabled = true;
|
|
|
|
|
@ -84,7 +84,7 @@ class _TodayAttendanceScreenState extends State<TodayAttendanceScreen> {
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
data.fetchAttendanceTracking();
|
|
|
|
|
data.fetchAttendanceTracking(context);
|
|
|
|
|
},
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.ac_unit,
|
|
|
|
|
@ -190,24 +190,13 @@ class _TodayAttendanceScreenState extends State<TodayAttendanceScreen> {
|
|
|
|
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 1 / 1, crossAxisSpacing: 8, mainAxisSpacing: 8),
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, () {
|
|
|
|
|
showNfcReader(context, onNcfScan: (String? nfcId) async {
|
|
|
|
|
print(nfcId);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 2, nfcValue: nfcId ?? "");
|
|
|
|
|
bool status = await model.fetchAttendanceTracking();
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
print(ex);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.handleException(ex, (msg) {
|
|
|
|
|
Utils.confirmDialog(context, msg);
|
|
|
|
|
if (isNfcLocationEnabled) {
|
|
|
|
|
Location.getCurrentLocation((LatLng? latlng) {
|
|
|
|
|
performNfcAttendance(model, lat: latlng?.latitude.toString() ?? "", lng: latlng?.longitude.toString() ?? "");
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
performNfcAttendance(model);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// Location.getCurrentLocation((LatLng? latlng) {
|
|
|
|
|
// print(latlng!.longitude.toString());
|
|
|
|
|
// });
|
|
|
|
|
}),
|
|
|
|
|
attendanceMethod("Wifi", "assets/images/wufu.svg", isWifiEnabled, () {}),
|
|
|
|
|
],
|
|
|
|
|
@ -244,6 +233,30 @@ class _TodayAttendanceScreenState extends State<TodayAttendanceScreen> {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> performNfcAttendance(DashboardProviderModel model, {String lat = "0", String lng = "0"}) async {
|
|
|
|
|
if (isNfcLocationEnabled) {
|
|
|
|
|
print("nfc location enabled");
|
|
|
|
|
} else {
|
|
|
|
|
print("nfc not location enabled");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
showNfcReader(context, onNcfScan: (String? nfcId) async {
|
|
|
|
|
print(nfcId);
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 2, nfcValue: nfcId ?? "", isGpsRequired: isNfcLocationEnabled, lat: lat, long: lng);
|
|
|
|
|
bool status = await model.fetchAttendanceTracking(context);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
print(ex);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.handleException(ex, context, (msg) {
|
|
|
|
|
Utils.confirmDialog(context, msg);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget attendanceMethod(String title, String image, bool isEnabled, VoidCallback onPress) => Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.circular(15),
|
|
|
|
|
|