nfc_foreground_dispatch 0.0.2
nfc_foreground_dispatch: ^0.0.2 copied to clipboard
Enables Android NFC foreground dispatch to suppress the system NFC handler, allowing your app to claim NFC priority.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:nfc_foreground_dispatch/nfc_foreground_dispatch.dart';
void main() => runApp(const MyApp());
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _status = 'NFC Foreground Dispatch: OFF';
Future<void> _enable() async {
final result = await NfcForegroundDispatch.enable();
setState(() {
_status = result
? 'NFC Foreground Dispatch: ON'
: 'Failed to enable';
});
}
Future<void> _disable() async {
final result = await NfcForegroundDispatch.disable();
setState(() {
_status = result
? 'NFC Foreground Dispatch: OFF'
: 'Failed to disable';
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('NFC Foreground Dispatch Example')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(_status),
const SizedBox(height: 20),
ElevatedButton(onPressed: _enable, child: const Text('Enable')),
const SizedBox(height: 10),
ElevatedButton(onPressed: _disable, child: const Text('Disable')),
],
),
),
),
);
}
}