nfc_check 1.0.0
nfc_check: ^1.0.0 copied to clipboard
A Flutter plugin to check for NFC and HCE support on Android devices, and open NFC settings.
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:nfc_check/nfc_check.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _nfcCheckPlugin = NfcCheck();
bool isNfcSupported = false;
bool isNfcEnabled = false;
bool isHceSupported = false;
@override
void initState() {
super.initState();
initPlatformState();
}
Future<void> initPlatformState() async {
isNfcSupported = await _nfcCheckPlugin.isNfcSupported();
isNfcEnabled = await _nfcCheckPlugin.isNfcEnabled();
isHceSupported = await _nfcCheckPlugin.isHceSupported();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('NFC Check'),
centerTitle: true,
elevation: 2,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('NFC Supported: $isNfcSupported'),
Text('NFC Enabled: $isNfcEnabled'),
Text('HCE Supported: $isHceSupported'),
const SizedBox(height: 32),
ElevatedButton(
child: const Text('Open NFC Settings'),
onPressed: () async {
try {
await _nfcCheckPlugin.openNfcSettings();
} catch (e) {
if (kDebugMode) {
print(e.toString());
}
}
},
),
],
),
),
),
);
}
}