From e6405b22515bac4f4d213270adc87e798bba51a3 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Thu, 29 Sep 2022 09:55:48 +0300 Subject: [PATCH] NFC fixes --- ios/Runner/Info.plist | 4 ++++ lib/classes/consts.dart | 4 ++-- lib/widgets/mark_attendance_widget.dart | 12 ++++++++---- lib/widgets/nfc/nfc_reader_sheet.dart | 15 +++++++++++++-- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 13cb83e..0534f2b 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -67,5 +67,9 @@ UIViewControllerBasedStatusBarAppearance + com.apple.developer.nfc.readersession.felica.systemcodes + + 0000 + diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 12f818e..17bd143 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -1,7 +1,7 @@ class ApiConsts { //static String baseUrl = "http://10.200.204.20:2801/"; // Local server - static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server - // static String baseUrl = "https://hmgwebservices.com"; // Live server + // static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server + static String baseUrl = "https://hmgwebservices.com"; // Live server static String baseUrlServices = baseUrl + "/Services/"; // server // static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/"; diff --git a/lib/widgets/mark_attendance_widget.dart b/lib/widgets/mark_attendance_widget.dart index 97bb76c..08e7c5e 100644 --- a/lib/widgets/mark_attendance_widget.dart +++ b/lib/widgets/mark_attendance_widget.dart @@ -158,16 +158,19 @@ class _MarkAttendanceWidgetState extends State { bool isConnected = await WiFiForIoTPlugin.connect(AppState().getMohemmWifiSSID ?? "", password: AppState().getMohemmWifiPassword ?? "", joinOnce: true, security: NetworkSecurity.WPA, withInternet: false); if (isConnected) { + Utils.showLoading(context); await WiFiForIoTPlugin.forceWifiUsage(true); - Utils.showLoading(context); + await Future.delayed(Duration(seconds: 1)); + try { GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 3, nfcValue: "", isGpsRequired: isWifiLocationEnabled, lat: lat, long: lng); bool status = await model.fetchAttendanceTracking(context); Utils.hideLoading(context); - await closeWifiRequest(); + // await closeWifiRequest(); } catch (ex) { - await closeWifiRequest(); + print("performWifiAttendance: "+ex.toString()); + // await closeWifiRequest(); Utils.hideLoading(context); Utils.handleException(ex, context, (msg) { Utils.confirmDialog(context, msg); @@ -179,7 +182,8 @@ class _MarkAttendanceWidgetState extends State { } Future closeWifiRequest() async { - await WiFiForIoTPlugin.forceWifiUsage(false); + // await WiFiForIoTPlugin.forceWifiUsage(false); + // Future.delayed(Duration(seconds: 2)); return await WiFiForIoTPlugin.disconnect(); } diff --git a/lib/widgets/nfc/nfc_reader_sheet.dart b/lib/widgets/nfc/nfc_reader_sheet.dart index c0d0edd..4ac055b 100644 --- a/lib/widgets/nfc/nfc_reader_sheet.dart +++ b/lib/widgets/nfc/nfc_reader_sheet.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:io'; import 'package:flutter/material.dart'; import 'package:nfc_manager/nfc_manager.dart'; @@ -41,9 +42,13 @@ class _NfcLayoutState extends State { NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async { print(tag.data); - var f = MifareUltralight(tag: tag, identifier: tag.data["nfca"]["identifier"], type: 2, maxTransceiveLength: 252, timeout: 22); + var f; + if (Platform.isAndroid) { + f = MifareUltralight(tag: tag, identifier: tag.data["nfca"]["identifier"], type: 2, maxTransceiveLength: 252, timeout: 22); + } else { + f = MifareUltralight(tag: tag, identifier: tag.data["mifare"]["identifier"], type: 2, maxTransceiveLength: 252, timeout: 22); + } String identifier = f.identifier.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); - // print(identifier); // => 0428fcf2255e81 nfcId = identifier; setState(() { @@ -54,6 +59,12 @@ class _NfcLayoutState extends State { Future.delayed(const Duration(seconds: 1), () { NfcManager.instance.stopSession(); Navigator.pop(context); + // if (Platform.isAndroid) { + // Navigator.pop(context); + // } else { + // Navigator.pop(context); + // Navigator.pop(context); + // } widget.onNcfScan(nfcId); }); }).catchError((err) {