MissingPluginException for nfcAvailability only in Android release build (works after restart)

6 days ago 7
ARTICLE AD BOX

I am getting error in Android release build

MissingPluginException (No implementation found for method getNFCAvailability)

enter image description here

and NFC starts working again only after restart

Device : Samsung Galaxy A23

Version : flutter_nfc_kit: ^3.6.2

void startNfc({required BuildContext context}) async { final locale = AppLocalizations.of(context)!; try { final NFCAvailability nfcStatus = await FlutterNfcKit.nfcAvailability; switch (nfcStatus) { case NFCAvailability.available: break; case NFCAvailability.disabled: AppUtils.showToast( message: locale.nfcDisabled, backgroundColor: AppColors.errorToastColor, textColor: AppColors.toastTextColor, ); return; case NFCAvailability.not_supported: AppUtils.showToast( message: locale.nfvIsNotSupportedOnThisDevice, backgroundColor: AppColors.errorToastColor, textColor: AppColors.toastTextColor, ); return; } try { await FlutterNfcKit.finish(); } catch (e) { log("====> $e"); } if (_isNfcOn) { stopNfc(); return; } _isNfcOn = true; notifyListeners(); while (_isNfcOn) { try { final tag = await FlutterNfcKit.poll( readIso14443A: true, readIso15693: true, readIso14443B: true, readIso18092: true, timeout: const Duration(seconds: 15), ); log("NFC TAG ID ${tag.id}"); debugPrint("NFC TAG ID ${tag.id}"); String finalNFCValue; if (tag.type == NFCTagType.mifare_classic) { final List<int> bytes = []; for (int i = 0; i < tag.id.length; i += 2) { bytes.add( int.parse(tag.id.substring(i, i + 2), radix: 16), ); } int decodedValue = 0; for (int i = 0; i < bytes.length; i++) { decodedValue += bytes[i] * pow(256, i).toInt(); } finalNFCValue = decodedValue.toString(); } else { finalNFCValue = BigInt.parse(tag.id, radix: 16).toString(); } await FlutterNfcKit.finish(); if (Platform.isIOS) { await Future.delayed(const Duration(seconds: 2)); } await apiCall( cardId: finalNFCValue, isNfc: true, ); } on PlatformException catch (e) { if (Platform.isAndroid && e.code == "500") { stopNfc(); AppUtils.showToast( message: locale.pleaseRestartYourApp, backgroundColor: AppColors.errorToastColor, textColor: AppColors.toastTextColor, ); } if (e.code == "409") { stopNfc(); } } catch (e) { log("⚠️ NFC Read Error: $e"); await FlutterNfcKit.finish(); await Future.delayed( const Duration(milliseconds: 500), ); } } } catch (e) { AppUtils.showToast( message: e.toString(), backgroundColor: AppColors.errorToastColor, textColor: AppColors.toastTextColor, ); log("Session Error: $e"); } }
Read Entire Article