MissingPluginException для nfcAvailability только в сборке выпуска Android (работает после перезапуска)Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 MissingPluginException для nfcAvailability только в сборке выпуска Android (работает после перезапуска)

Сообщение Anonymous »

Я получаю сообщение об ошибке в сборке выпуска Android

MissingPluginException (реализация метода
getNFCAvailability не найдена)

Изображение

и NFC снова начинает работать только после перезагрузки
Устройство: Samsung Galaxy A23
Версия: 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 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 * 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");
}
}


Подробнее здесь: https://stackoverflow.com/questions/798 ... uild-works
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»