From 0d7240792afa3f88888899fec23c262b7c236bd5 Mon Sep 17 00:00:00 2001 From: WaseemAbbasi22 <50428976+WaseemAbbasi22@users.noreply.github.com> Date: Wed, 18 Mar 2026 11:56:20 +0300 Subject: [PATCH] NFC manager package replaced with FlutterNFCKit --- ios/Runner.xcodeproj/project.pbxproj | 14 +- lib/dashboard_latest/dashboard_view.dart | 11 +- lib/helper/utils.dart | 80 +-- .../non_hmg_employee_swipe_view.dart | 18 +- .../non_hmg_employee_swipe_view.dart | 16 +- lib/new_views/swipe_module/swipe_view.dart | 24 +- .../utils/swipe_general_utils.dart | 80 +-- lib/nfc/nfc_reader_sheet.dart | 496 +++++++++--------- pubspec.lock | 18 +- pubspec.yaml | 2 +- 10 files changed, 403 insertions(+), 356 deletions(-) diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 159a3dcf..f17d91b1 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -233,10 +233,14 @@ inputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist", ); + inputPaths = ( + ); name = "[CP] Copy Pods Resources"; outputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist", ); + outputPaths = ( + ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; @@ -265,10 +269,14 @@ inputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", ); + inputPaths = ( + ); name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", ); + outputPaths = ( + ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; @@ -394,7 +402,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 5; - DEVELOPMENT_TEAM = 99Z3UD3LJM; + DEVELOPMENT_TEAM = F3XW3W7X9G; ENABLE_BITCODE = NO; ENABLE_USER_SCRIPT_SANDBOXING = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -612,7 +620,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 5; - DEVELOPMENT_TEAM = 99Z3UD3LJM; + DEVELOPMENT_TEAM = F3XW3W7X9G; ENABLE_BITCODE = NO; ENABLE_USER_SCRIPT_SANDBOXING = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -716,7 +724,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 5; - DEVELOPMENT_TEAM = 99Z3UD3LJM; + DEVELOPMENT_TEAM = F3XW3W7X9G; ENABLE_BITCODE = NO; ENABLE_USER_SCRIPT_SANDBOXING = NO; INFOPLIST_FILE = Runner/Info.plist; diff --git a/lib/dashboard_latest/dashboard_view.dart b/lib/dashboard_latest/dashboard_view.dart index bf9b5a71..64ee035d 100644 --- a/lib/dashboard_latest/dashboard_view.dart +++ b/lib/dashboard_latest/dashboard_view.dart @@ -2,7 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:nfc_manager/nfc_manager.dart'; +import 'package:flutter_nfc_kit/flutter_nfc_kit.dart'; import 'package:provider/provider.dart'; import 'package:test_sa/controllers/notification/firebase_notification_manger.dart'; import 'package:test_sa/controllers/notification/notification_manger.dart'; @@ -105,6 +105,7 @@ class _DashboardViewState extends State { Widget build(BuildContext context) { final user = Provider.of(context, listen: false).user; bool isEngineer = (user?.type) == UsersTypes.engineer; + ///Need to check which info need to show on dashboard for quality user. bool isQualityUser = (user?.type) == UsersTypes.qualityUser; @@ -141,7 +142,13 @@ class _DashboardViewState extends State { bottom: 20.toScreenHeight, child: GestureDetector( onTap: () async { - bool isNfcSupported = await NfcManager.instance.isAvailable(); + var availability = await FlutterNfcKit.nfcAvailability; + bool isNfcSupported = false; + if (availability != NFCAvailability.available) { + isNfcSupported = false; + } else { + isNfcSupported = true; + } SwipeGeneralUtils.instance.showSwipeTypeBottomSheetSheet(isNfcSupported: isNfcSupported); }, child: CircularAnimatedContainer( diff --git a/lib/helper/utils.dart b/lib/helper/utils.dart index d35cd4cb..02461c88 100644 --- a/lib/helper/utils.dart +++ b/lib/helper/utils.dart @@ -19,7 +19,7 @@ import 'package:google_api_availability/google_api_availability.dart'; // import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; // import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.dart'; // import 'package:mohem_flutter_app/widgets/loading_dialog.dart'; -import 'package:nfc_manager/nfc_manager.dart'; +// import 'package:nfc_manager/nfc_manager.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:test_sa/new_views/common_widgets/app_lazy_loading.dart'; import 'package:test_sa/views/widgets/dialogs/confirm_dialog.dart'; @@ -415,45 +415,45 @@ class Utils { // } // return selectedDate; // } - - static void readNFc({required Function(String) onRead}) { - NfcManager.instance.startSession( - onDiscovered: (NfcTag tag) async { - String identifier = ''; - - try { - final dynamic tagDynamic = tag; - final Map tagData = Map.from(tagDynamic.data as Map); - - if (Platform.isAndroid) { - if (tagData.containsKey('nfca')) { - final nfcaData = tagData['nfca'] as Map; - if (nfcaData.containsKey('identifier')) { - final List idBytes = List.from(nfcaData['identifier'] as List); - identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); - } - } - } else { - if (tagData.containsKey('mifare')) { - final mifareData = tagData['mifare'] as Map; - if (mifareData.containsKey('identifier')) { - final List idBytes = List.from(mifareData['identifier'] as List); - identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); - } - } - } - } catch (e) { - print('Error reading NFC: $e'); - } - - NfcManager.instance.stopSession(); - onRead(identifier); - }, - pollingOptions: {NfcPollingOption.iso14443}, - ).catchError((err) { - print(err); - }); - } +//Unused code.... + // static void readNFc({required Function(String) onRead}) { + // NfcManager.instance.startSession( + // onDiscovered: (NfcTag tag) async { + // String identifier = ''; + // + // try { + // final dynamic tagDynamic = tag; + // final Map tagData = Map.from(tagDynamic.data as Map); + // + // if (Platform.isAndroid) { + // if (tagData.containsKey('nfca')) { + // final nfcaData = tagData['nfca'] as Map; + // if (nfcaData.containsKey('identifier')) { + // final List idBytes = List.from(nfcaData['identifier'] as List); + // identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + // } + // } + // } else { + // if (tagData.containsKey('mifare')) { + // final mifareData = tagData['mifare'] as Map; + // if (mifareData.containsKey('identifier')) { + // final List idBytes = List.from(mifareData['identifier'] as List); + // identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); + // } + // } + // } + // } catch (e) { + // print('Error reading NFC: $e'); + // } + // + // NfcManager.instance.stopSession(); + // onRead(identifier); + // }, + // pollingOptions: {NfcPollingOption.iso14443}, + // ).catchError((err) { + // print(err); + // }); + // } //HUAWEI DECISION MAKING static Future isGoogleServicesAvailable() async { diff --git a/lib/new_views/pages/land_page/non_hmg_employee_swipe_view.dart b/lib/new_views/pages/land_page/non_hmg_employee_swipe_view.dart index 0c0c4c14..72f1eae3 100644 --- a/lib/new_views/pages/land_page/non_hmg_employee_swipe_view.dart +++ b/lib/new_views/pages/land_page/non_hmg_employee_swipe_view.dart @@ -1,6 +1,9 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; -import 'package:nfc_manager/nfc_manager.dart'; +import 'package:flutter_nfc_kit/flutter_nfc_kit.dart'; import 'package:test_sa/extensions/context_extension.dart'; +import 'package:test_sa/extensions/string_extensions.dart'; import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/new_views/app_style/app_color.dart'; @@ -24,7 +27,18 @@ class _NonHmgEmployeeSwipeViewState extends State { } void checkForNfcAndLocationPermission() async { - isNfcEnabled = await NfcManager.instance.isAvailable(); + // isNfcEnabled = await NfcManager.instance.isAvailable(); + try { + var availability = await FlutterNfcKit.nfcAvailability; + if (availability != NFCAvailability.available) { + isNfcEnabled = false; + } else { + isNfcEnabled = true; + } + } catch (e) { + log('error checking NFC availability: $e'); + isNfcEnabled = false; + } } @override diff --git a/lib/new_views/swipe_module/non_hmg_employee_swipe_view.dart b/lib/new_views/swipe_module/non_hmg_employee_swipe_view.dart index 8f392199..dc90a2d1 100644 --- a/lib/new_views/swipe_module/non_hmg_employee_swipe_view.dart +++ b/lib/new_views/swipe_module/non_hmg_employee_swipe_view.dart @@ -1,5 +1,6 @@ +import 'dart:developer'; import 'package:flutter/material.dart'; -import 'package:nfc_manager/nfc_manager.dart'; +import 'package:flutter_nfc_kit/flutter_nfc_kit.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; @@ -24,7 +25,18 @@ class _NonHmgEmployeeSwipeViewState extends State { } void checkForNfcAndLocationPermission() async { - isNfcEnabled = await NfcManager.instance.isAvailable(); + // isNfcEnabled = await NfcManager.instance.isAvailable(); + try { + var availability = await FlutterNfcKit.nfcAvailability; + if (availability != NFCAvailability.available) { + isNfcEnabled = false; + } else { + isNfcEnabled = true; + } + } catch (e) { + log('error checking NFC availability: $e'); + isNfcEnabled = false; + } } @override diff --git a/lib/new_views/swipe_module/swipe_view.dart b/lib/new_views/swipe_module/swipe_view.dart index e6412ea4..55c06a65 100644 --- a/lib/new_views/swipe_module/swipe_view.dart +++ b/lib/new_views/swipe_module/swipe_view.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:nfc_manager/nfc_manager.dart'; +import 'package:flutter_nfc_kit/flutter_nfc_kit.dart'; import 'package:provider/provider.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; @@ -119,12 +119,32 @@ class _SwipeViewState extends State { SwipeHistoryView().expanded, ], ), + // void checkForNfcAndLocationPermission() async { + // // isNfcEnabled = await NfcManager.instance.isAvailable(); + // try { + // var availability = await FlutterNfcKit.nfcAvailability; + // if (availability != NFCAvailability.available) { + // isNfcEnabled = false; + // } else { + // isNfcEnabled = true; + // } + // } catch (e) { + // log('error checking NFC availability: $e'); + // isNfcEnabled = false; + // } + // } Positioned( right: 20.toScreenWidth, bottom: 60.toScreenHeight, child: GestureDetector( onTap: () async { - bool isNfcSupported = await NfcManager.instance.isAvailable(); + var availability = await FlutterNfcKit.nfcAvailability; + bool isNfcSupported = false; + if (availability != NFCAvailability.available) { + isNfcSupported = false; + } else { + isNfcSupported = true; + } SwipeGeneralUtils.instance.showSwipeTypeBottomSheetSheet(isNfcSupported: isNfcSupported); }, child: CircularAnimatedContainer( diff --git a/lib/new_views/swipe_module/utils/swipe_general_utils.dart b/lib/new_views/swipe_module/utils/swipe_general_utils.dart index 48fb6c8e..5bb11008 100644 --- a/lib/new_views/swipe_module/utils/swipe_general_utils.dart +++ b/lib/new_views/swipe_module/utils/swipe_general_utils.dart @@ -10,7 +10,8 @@ import 'package:geolocator/geolocator.dart'; import 'package:google_api_availability/google_api_availability.dart'; import 'package:huawei_location/huawei_location.dart'; import 'package:intl/intl.dart'; -import 'package:nfc_manager/nfc_manager.dart'; + +// import 'package:nfc_manager/nfc_manager.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:provider/provider.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -408,7 +409,6 @@ class SwipeGeneralUtils { try { showNfcReader(context, onNcfScan: (String? nfcId) async { log('nfc id from sheet: $nfcId'); - if (nfcId == null || nfcId.isEmpty) return; try { await _processNfcAttendance(nfcId, latitude, longitude, context); @@ -697,44 +697,44 @@ class SwipeGeneralUtils { } //older code.. - void readNFc({Function(String)? onRead}) { - NfcManager.instance.startSession( - onDiscovered: (NfcTag tag) async { - String identifier = ''; - - try { - final dynamic tagDynamic = tag; - final Map tagData = Map.from(tagDynamic.data as Map); - - if (Platform.isAndroid) { - if (tagData.containsKey('nfca')) { - final nfcaData = tagData['nfca'] as Map; - if (nfcaData.containsKey('identifier')) { - final List idBytes = List.from(nfcaData['identifier'] as List); - identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); - } - } - } else { - if (tagData.containsKey('mifare')) { - final mifareData = tagData['mifare'] as Map; - if (mifareData.containsKey('identifier')) { - final List idBytes = List.from(mifareData['identifier'] as List); - identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); - } - } - } - } catch (e) { - print('Error reading NFC: $e'); - } - - NfcManager.instance.stopSession(); - onRead!(identifier); - }, - pollingOptions: {NfcPollingOption.iso14443}, - ).catchError((err) { - print(err); - }); - } +// void readNFc({Function(String)? onRead}) { +// NfcManager.instance.startSession( +// onDiscovered: (NfcTag tag) async { +// String identifier = ''; +// +// try { +// final dynamic tagDynamic = tag; +// final Map tagData = Map.from(tagDynamic.data as Map); +// +// if (Platform.isAndroid) { +// if (tagData.containsKey('nfca')) { +// final nfcaData = tagData['nfca'] as Map; +// if (nfcaData.containsKey('identifier')) { +// final List idBytes = List.from(nfcaData['identifier'] as List); +// identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); +// } +// } +// } else { +// if (tagData.containsKey('mifare')) { +// final mifareData = tagData['mifare'] as Map; +// if (mifareData.containsKey('identifier')) { +// final List idBytes = List.from(mifareData['identifier'] as List); +// identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); +// } +// } +// } +// } catch (e) { +// print('Error reading NFC: $e'); +// } +// +// NfcManager.instance.stopSession(); +// onRead!(identifier); +// }, +// pollingOptions: {NfcPollingOption.iso14443}, +// ).catchError((err) { +// print(err); +// }); +// } //HUAWEI DECISION MAKING Future isGoogleServicesAvailable() async { diff --git a/lib/nfc/nfc_reader_sheet.dart b/lib/nfc/nfc_reader_sheet.dart index 151b1ebb..e9a8fc50 100644 --- a/lib/nfc/nfc_reader_sheet.dart +++ b/lib/nfc/nfc_reader_sheet.dart @@ -1,247 +1,249 @@ -import 'dart:async'; -import 'dart:io'; - -import 'package:flutter/material.dart'; -import 'package:nfc_manager/nfc_manager.dart'; - -void showNfcReader(BuildContext context, {required Function(String? nfcId) onNcfScan}) { - showModalBottomSheet( - context: context, - enableDrag: false, - isDismissible: false, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.only(topLeft: Radius.circular(12), topRight: Radius.circular(12)), - ), - backgroundColor: Colors.white, - builder: (context) { - return NfcLayout( - onNcfScan: onNcfScan, - ); - }, - ); -} - -class NfcLayout extends StatefulWidget { - final Function(String? nfcId) onNcfScan; - - const NfcLayout({super.key, required this.onNcfScan}); - - @override - _NfcLayoutState createState() => _NfcLayoutState(); -} - -class _NfcLayoutState extends State { - bool _reading = false; - Widget? mainWidget; - String? nfcId; - - @override - void initState() { - super.initState(); - - NfcManager.instance.startSession( - onDiscovered: (NfcTag tag) async { - String? identifier; - - // Access tag identifier from the tag data - // In nfc_manager 4.1.1, access data via dynamic cast to bypass protected member - try { - final dynamic tagDynamic = tag; - final Map tagData = Map.from(tagDynamic.data as Map); - - if (Platform.isAndroid) { - // For Android, try NfcA technology first - if (tagData.containsKey('nfca')) { - final nfcaData = tagData['nfca'] as Map; - if (nfcaData.containsKey('identifier')) { - final List idBytes = List.from(nfcaData['identifier'] as List); - identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); - } - } - // Fallback to other technologies if NfcA is not available - if (identifier == null && tagData.containsKey('nfcb')) { - final nfcbData = tagData['nfcb'] as Map; - if (nfcbData.containsKey('identifier')) { - final List idBytes = List.from(nfcbData['identifier'] as List); - identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); - } - } - } else { - // For iOS, try MiFare technology - if (tagData.containsKey('mifare')) { - final mifareData = tagData['mifare'] as Map; - if (mifareData.containsKey('identifier')) { - final List idBytes = List.from(mifareData['identifier'] as List); - identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); - } - } - // Fallback to iso15693 for iOS - if (identifier == null && tagData.containsKey('iso15693')) { - final iso15693Data = tagData['iso15693'] as Map; - if (iso15693Data.containsKey('identifier')) { - final List idBytes = List.from(iso15693Data['identifier'] as List); - identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); - } - } - } - - // Universal fallback: try Ndef if available - if (identifier == null && tagData.containsKey('ndef')) { - final ndefData = tagData['ndef'] as Map; - if (ndefData.containsKey('identifier')) { - final List idBytes = List.from(ndefData['identifier'] as List); - identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); - } - } - } catch (e) { - print('Error reading NFC tag: $e'); - } - - nfcId = identifier; - - setState(() { - _reading = true; - mainWidget = doneNfc(); - }); - - Future.delayed(const Duration(seconds: 1), () { - NfcManager.instance.stopSession(); - Navigator.pop(context); - widget.onNcfScan(nfcId); - }); - }, - pollingOptions: {NfcPollingOption.iso14443}, - ).catchError((err) { - print(err); - }); - } - - @override - Widget build(BuildContext context) { - (mainWidget == null && !_reading) ? mainWidget = scanNfc() : mainWidget = doneNfc(); - return AnimatedSwitcher(duration: Duration(milliseconds: 500), child: mainWidget); - } - - Widget scanNfc() { - return Container( - key: ValueKey(1), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox( - height: 30, - ), - Text( - "Ready To Scan", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 24, - ), - ), - SizedBox( - height: 30, - ), - Image.asset( - "assets/images/nfc_dummy.png", - height: MediaQuery.of(context).size.width / 3, - width: double.infinity, - ), - SizedBox( - height: 30, - ), - Text( - "Approach an NFC Tag", - style: TextStyle( - fontSize: 18, - ), - ), - SizedBox( - height: 30, - ), - ButtonTheme( - minWidth: MediaQuery.of(context).size.width / 1.2, - height: 45.0, - buttonColor: Colors.grey[300], - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(6), - ), - child: TextButton( - onPressed: () { - NfcManager.instance.stopSession(); - Navigator.pop(context); - }, - // elevation: 0, - child: Text("CANCEL"), - ), - ), - SizedBox( - height: 30, - ), - ], - ), - ); - } - - Widget doneNfc() { - return Container( - key: ValueKey(2), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox( - height: 30, - ), - Text( - "Successfully Scanned", - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 24, - ), - ), - SizedBox( - height: 30, - ), - Image.asset( - // "assets/icons/nfc/ic_done.png", - "assets/images/done_dummy.jpeg", - height: MediaQuery.of(context).size.width / 3, - width: double.infinity, - ), - SizedBox( - height: 30, - ), - Text( - "Approach an NFC Tag", - style: TextStyle( - fontSize: 18, - ), - ), - SizedBox( - height: 30, - ), - ButtonTheme( - minWidth: MediaQuery.of(context).size.width / 1.2, - height: 45.0, - buttonColor: Colors.grey[300], - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(6), - ), - child: TextButton( - // onPressed: () { - // _stream?.cancel(); - // widget.onNcfScan(nfcId); - // Navigator.pop(context); - // }, - onPressed: null, - // elevation: 0, - child: Text("DONE"), - ), - ), - SizedBox( - height: 30, - ), - ], - ), - ); - } -} +//TODO delete unused file + +// import 'dart:async'; +// import 'dart:io'; +// +// import 'package:flutter/material.dart'; +// // import 'package:nfc_manager/nfc_manager.dart'; +// +// void showNfcReader(BuildContext context, {required Function(String? nfcId) onNcfScan}) { +// showModalBottomSheet( +// context: context, +// enableDrag: false, +// isDismissible: false, +// shape: const RoundedRectangleBorder( +// borderRadius: BorderRadius.only(topLeft: Radius.circular(12), topRight: Radius.circular(12)), +// ), +// backgroundColor: Colors.white, +// builder: (context) { +// return NfcLayout( +// onNcfScan: onNcfScan, +// ); +// }, +// ); +// } +// +// class NfcLayout extends StatefulWidget { +// final Function(String? nfcId) onNcfScan; +// +// const NfcLayout({super.key, required this.onNcfScan}); +// +// @override +// _NfcLayoutState createState() => _NfcLayoutState(); +// } +// +// class _NfcLayoutState extends State { +// bool _reading = false; +// Widget? mainWidget; +// String? nfcId; +// +// @override +// void initState() { +// super.initState(); +// +// NfcManager.instance.startSession( +// onDiscovered: (NfcTag tag) async { +// String? identifier; +// +// // Access tag identifier from the tag data +// // In nfc_manager 4.1.1, access data via dynamic cast to bypass protected member +// try { +// final dynamic tagDynamic = tag; +// final Map tagData = Map.from(tagDynamic.data as Map); +// +// if (Platform.isAndroid) { +// // For Android, try NfcA technology first +// if (tagData.containsKey('nfca')) { +// final nfcaData = tagData['nfca'] as Map; +// if (nfcaData.containsKey('identifier')) { +// final List idBytes = List.from(nfcaData['identifier'] as List); +// identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); +// } +// } +// // Fallback to other technologies if NfcA is not available +// if (identifier == null && tagData.containsKey('nfcb')) { +// final nfcbData = tagData['nfcb'] as Map; +// if (nfcbData.containsKey('identifier')) { +// final List idBytes = List.from(nfcbData['identifier'] as List); +// identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); +// } +// } +// } else { +// // For iOS, try MiFare technology +// if (tagData.containsKey('mifare')) { +// final mifareData = tagData['mifare'] as Map; +// if (mifareData.containsKey('identifier')) { +// final List idBytes = List.from(mifareData['identifier'] as List); +// identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); +// } +// } +// // Fallback to iso15693 for iOS +// if (identifier == null && tagData.containsKey('iso15693')) { +// final iso15693Data = tagData['iso15693'] as Map; +// if (iso15693Data.containsKey('identifier')) { +// final List idBytes = List.from(iso15693Data['identifier'] as List); +// identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); +// } +// } +// } +// +// // Universal fallback: try Ndef if available +// if (identifier == null && tagData.containsKey('ndef')) { +// final ndefData = tagData['ndef'] as Map; +// if (ndefData.containsKey('identifier')) { +// final List idBytes = List.from(ndefData['identifier'] as List); +// identifier = idBytes.map((e) => e.toRadixString(16).padLeft(2, '0')).join(''); +// } +// } +// } catch (e) { +// print('Error reading NFC tag: $e'); +// } +// +// nfcId = identifier; +// +// setState(() { +// _reading = true; +// mainWidget = doneNfc(); +// }); +// +// Future.delayed(const Duration(seconds: 1), () { +// NfcManager.instance.stopSession(); +// Navigator.pop(context); +// widget.onNcfScan(nfcId); +// }); +// }, +// pollingOptions: {NfcPollingOption.iso14443}, +// ).catchError((err) { +// print(err); +// }); +// } +// +// @override +// Widget build(BuildContext context) { +// (mainWidget == null && !_reading) ? mainWidget = scanNfc() : mainWidget = doneNfc(); +// return AnimatedSwitcher(duration: Duration(milliseconds: 500), child: mainWidget); +// } +// +// Widget scanNfc() { +// return Container( +// key: ValueKey(1), +// child: Column( +// mainAxisSize: MainAxisSize.min, +// children: [ +// SizedBox( +// height: 30, +// ), +// Text( +// "Ready To Scan", +// style: TextStyle( +// fontWeight: FontWeight.bold, +// fontSize: 24, +// ), +// ), +// SizedBox( +// height: 30, +// ), +// Image.asset( +// "assets/images/nfc_dummy.png", +// height: MediaQuery.of(context).size.width / 3, +// width: double.infinity, +// ), +// SizedBox( +// height: 30, +// ), +// Text( +// "Approach an NFC Tag", +// style: TextStyle( +// fontSize: 18, +// ), +// ), +// SizedBox( +// height: 30, +// ), +// ButtonTheme( +// minWidth: MediaQuery.of(context).size.width / 1.2, +// height: 45.0, +// buttonColor: Colors.grey[300], +// shape: RoundedRectangleBorder( +// borderRadius: BorderRadius.circular(6), +// ), +// child: TextButton( +// onPressed: () { +// NfcManager.instance.stopSession(); +// Navigator.pop(context); +// }, +// // elevation: 0, +// child: Text("CANCEL"), +// ), +// ), +// SizedBox( +// height: 30, +// ), +// ], +// ), +// ); +// } +// +// Widget doneNfc() { +// return Container( +// key: ValueKey(2), +// child: Column( +// mainAxisSize: MainAxisSize.min, +// children: [ +// SizedBox( +// height: 30, +// ), +// Text( +// "Successfully Scanned", +// style: TextStyle( +// fontWeight: FontWeight.bold, +// fontSize: 24, +// ), +// ), +// SizedBox( +// height: 30, +// ), +// Image.asset( +// // "assets/icons/nfc/ic_done.png", +// "assets/images/done_dummy.jpeg", +// height: MediaQuery.of(context).size.width / 3, +// width: double.infinity, +// ), +// SizedBox( +// height: 30, +// ), +// Text( +// "Approach an NFC Tag", +// style: TextStyle( +// fontSize: 18, +// ), +// ), +// SizedBox( +// height: 30, +// ), +// ButtonTheme( +// minWidth: MediaQuery.of(context).size.width / 1.2, +// height: 45.0, +// buttonColor: Colors.grey[300], +// shape: RoundedRectangleBorder( +// borderRadius: BorderRadius.circular(6), +// ), +// child: TextButton( +// // onPressed: () { +// // _stream?.cancel(); +// // widget.onNcfScan(nfcId); +// // Navigator.pop(context); +// // }, +// onPressed: null, +// // elevation: 0, +// child: Text("DONE"), +// ), +// ), +// SizedBox( +// height: 30, +// ), +// ], +// ), +// ); +// } +// } diff --git a/pubspec.lock b/pubspec.lock index 4a74d349..bf5bd198 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1070,14 +1070,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.4.0" - ndef_record: - dependency: transitive - description: - name: ndef_record - sha256: "210ffb12284961cab9e44b99462143316d9a20cd992581170706069ef77d74a6" - url: "https://pub.dev" - source: hosted - version: "1.4.2" nested: dependency: transitive description: @@ -1086,14 +1078,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" - nfc_manager: - dependency: "direct main" - description: - name: nfc_manager - sha256: "24c78b0e5702da53e7f8794d073624c0bee7cd99924f257cbd11f5d1c5866879" - url: "https://pub.dev" - source: hosted - version: "4.1.1" objective_c: dependency: transitive description: @@ -1964,5 +1948,5 @@ packages: source: hosted version: "3.1.3" sdks: - dart: ">=3.11.0 <4.0.0" + dart: ">=3.10.3 <4.0.0" flutter: ">=3.38.4" diff --git a/pubspec.yaml b/pubspec.yaml index 7f21ad2e..aa9cc791 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -96,7 +96,7 @@ dependencies: huawei_push: ^6.14.0+300 huawei_location: ^6.16.0+300 geolocator: ^9.0.2 - nfc_manager: ^4.1.1 +# nfc_manager: ^4.1.1 flutter_nfc_kit: ^3.6.2 wifi_iot: ^0.3.19+2