NFC fixes

merge-requests/1/merge
haroon amjad 3 years ago
parent eb29553d26
commit e6405b2251

@ -67,5 +67,9 @@
</array> </array>
<key>UIViewControllerBasedStatusBarAppearance</key> <key>UIViewControllerBasedStatusBarAppearance</key>
<false/> <false/>
<key>com.apple.developer.nfc.readersession.felica.systemcodes</key>
<array>
<string>0000</string>
</array>
</dict> </dict>
</plist> </plist>

@ -1,7 +1,7 @@
class ApiConsts { class ApiConsts {
//static String baseUrl = "http://10.200.204.20:2801/"; // Local server //static String baseUrl = "http://10.200.204.20:2801/"; // Local server
static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server // static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server
// static String baseUrl = "https://hmgwebservices.com"; // Live server static String baseUrl = "https://hmgwebservices.com"; // Live server
static String baseUrlServices = baseUrl + "/Services/"; // server static String baseUrlServices = baseUrl + "/Services/"; // server
// static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server // static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server
static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/"; static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/";

@ -158,16 +158,19 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
bool isConnected = bool isConnected =
await WiFiForIoTPlugin.connect(AppState().getMohemmWifiSSID ?? "", password: AppState().getMohemmWifiPassword ?? "", joinOnce: true, security: NetworkSecurity.WPA, withInternet: false); await WiFiForIoTPlugin.connect(AppState().getMohemmWifiSSID ?? "", password: AppState().getMohemmWifiPassword ?? "", joinOnce: true, security: NetworkSecurity.WPA, withInternet: false);
if (isConnected) { if (isConnected) {
Utils.showLoading(context);
await WiFiForIoTPlugin.forceWifiUsage(true); await WiFiForIoTPlugin.forceWifiUsage(true);
Utils.showLoading(context); await Future.delayed(Duration(seconds: 1));
try { try {
GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 3, nfcValue: "", isGpsRequired: isWifiLocationEnabled, lat: lat, long: lng); GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 3, nfcValue: "", isGpsRequired: isWifiLocationEnabled, lat: lat, long: lng);
bool status = await model.fetchAttendanceTracking(context); bool status = await model.fetchAttendanceTracking(context);
Utils.hideLoading(context); Utils.hideLoading(context);
await closeWifiRequest(); // await closeWifiRequest();
} catch (ex) { } catch (ex) {
await closeWifiRequest(); print("performWifiAttendance: "+ex.toString());
// await closeWifiRequest();
Utils.hideLoading(context); Utils.hideLoading(context);
Utils.handleException(ex, context, (msg) { Utils.handleException(ex, context, (msg) {
Utils.confirmDialog(context, msg); Utils.confirmDialog(context, msg);
@ -179,7 +182,8 @@ class _MarkAttendanceWidgetState extends State<MarkAttendanceWidget> {
} }
Future<bool> closeWifiRequest() async { Future<bool> closeWifiRequest() async {
await WiFiForIoTPlugin.forceWifiUsage(false); // await WiFiForIoTPlugin.forceWifiUsage(false);
// Future.delayed(Duration(seconds: 2));
return await WiFiForIoTPlugin.disconnect(); return await WiFiForIoTPlugin.disconnect();
} }

@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:nfc_manager/nfc_manager.dart'; import 'package:nfc_manager/nfc_manager.dart';
@ -41,9 +42,13 @@ class _NfcLayoutState extends State<NfcLayout> {
NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async { NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async {
print(tag.data); 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(''); String identifier = f.identifier.map((e) => e.toRadixString(16).padLeft(2, '0')).join('');
// print(identifier); // => 0428fcf2255e81
nfcId = identifier; nfcId = identifier;
setState(() { setState(() {
@ -54,6 +59,12 @@ class _NfcLayoutState extends State<NfcLayout> {
Future.delayed(const Duration(seconds: 1), () { Future.delayed(const Duration(seconds: 1), () {
NfcManager.instance.stopSession(); NfcManager.instance.stopSession();
Navigator.pop(context); Navigator.pop(context);
// if (Platform.isAndroid) {
// Navigator.pop(context);
// } else {
// Navigator.pop(context);
// Navigator.pop(context);
// }
widget.onNcfScan(nfcId); widget.onNcfScan(nfcId);
}); });
}).catchError((err) { }).catchError((err) {

Loading…
Cancel
Save