A Flutter application that reads and writes NFC NDEF tags using the flutter_nfc_kit package. Supports both Android and iOS platforms.
- ✅ Check NFC availability before scanning
- ✅ Read NFC tag UID and NDEF records
- ✅ Display tag ID, type, and payload information
- ✅ Write NDEF URL records to NFC tags
- ✅ Graceful error handling for timeouts and user cancellation
- ✅ Proper NFC session management
- ✅ Clean architecture with service layer separation
- ✅ Material Design UI with modern Flutter practices
- Flutter SDK (3.9.2 or higher)
- Android Studio / Xcode (for platform-specific setup)
- Physical device with NFC support (NFC cannot be tested on emulators)
- Clone the repository and navigate to the project directory:
cd nfc_app- Install dependencies:
flutter pub getThe Android configuration is already set up in android/app/src/main/AndroidManifest.xml:
- ✅ NFC permission (
android.permission.NFC) - ✅ NFC feature declaration (optional, not required)
Additional Steps:
-
Minimum SDK Version: Ensure your
android/app/build.gradle.ktshas a minimum SDK version of 21 or higher:android { defaultConfig { minSdk = 21 // or higher } } -
Enable NFC on Device:
- Go to Settings → Connected devices → Connection preferences → NFC
- Ensure NFC is enabled
-
Testing:
- NFC operations require a physical Android device
- NFC cannot be tested on Android emulators
- Ensure your device supports NFC (most modern Android devices do)
The iOS configuration has been set up with:
- ✅
NFCReaderUsageDescriptioninInfo.plist - ✅
com.apple.developer.nfc.readersession.formatsinInfo.plist - ✅
Runner.entitlementsfile with NFC capability
CRITICAL: Xcode Configuration Steps (Required for NFC to Work)
You MUST complete these steps in Xcode for NFC to work on iOS:
-
Open the Project in Xcode:
open ios/Runner.xcworkspace
⚠️ Important: Open.xcworkspace, NOT.xcodeproj -
Add NFC Capability:
- In Xcode, select the Runner project in the left sidebar
- Select the Runner target (under TARGETS)
- Click the "Signing & Capabilities" tab
- Click the "+ Capability" button (top left of the capabilities section)
- Search for and add "Near Field Communication Tag Reading"
- Verify that the capability appears with a checkmark
-
Link Entitlements File (if not automatically done):
- Still in "Signing & Capabilities" tab
- Look for "Code Signing Entitlements" field
- If empty, enter:
Runner/Runner.entitlements - Xcode should automatically link it when you add the capability, but verify it's set
-
Verify Build Settings:
- Go to "Build Settings" tab
- Search for "Code Signing Entitlements"
- Ensure it shows:
Runner/Runner.entitlements(for all configurations: Debug, Release, Profile)
-
Clean and Rebuild:
cd ios rm -rf Pods Podfile.lock pod install cd .. flutter clean flutter pub get
-
Minimum iOS Version:
- iOS 11.0 or higher is required for NFC functionality
- Your project is already configured for iOS 13.0+ (see
IPHONEOS_DEPLOYMENT_TARGET)
Why NFC Availability Check Fails Without This Setup:
On iOS, FlutterNfcKit.nfcAvailability will return notAvailable or throw an exception if:
- The NFC capability is not added in Xcode
- The entitlements file is not linked to the target
- The app is not signed with NFC entitlements
NFCReaderUsageDescriptionis missing from Info.plist
Even on iPhone 13 Pro (which definitely supports NFC), the availability check will fail without proper Xcode configuration.
Testing:
- NFC operations require a physical iOS device (iPhone 7 or later)
- NFC cannot be tested on iOS simulators
- After completing Xcode setup, rebuild and test on a real device
- Connect a physical device with NFC support
- Ensure NFC is enabled on the device
- Run the app:
flutter run- Tap the "Read Tag" button
- Hold your device near an NFC tag
- The app will display:
- Tag ID (UID)
- Tag Type (NFC-A, NFC-B, etc.)
- NDEF Records (if available)
- Tap the "Write URL" button
- Enter a URL in the dialog (e.g.,
https://example.com) - Hold your device near a writable NFC tag
- The app will write the URL as an NDEF record
lib/
├── main.dart # Main UI and app entry point
└── services/
└── nfc_service.dart # NFC service class with read/write logic
Service class that handles all NFC operations:
isNfcAvailable(): Checks if NFC is available on the devicereadTag(): Reads tag UID and NDEF recordswriteUrl(String url): Writes a URL as an NDEF recordcancel(): Cancels ongoing NFC operations
Material Design UI with:
- NFC availability status indicator
- Read and Write buttons
- Tag information display
- Error handling and user feedback
- Loading states during NFC operations
The app handles various error scenarios:
- NFC not available or disabled
- Timeout while waiting for tag
- User cancellation
- Tag read/write failures
- Invalid tag types
All errors are displayed to the user with clear messages.
The app properly manages NFC sessions:
- Sessions are automatically closed after each operation
- Sessions are cancelled when the user navigates away
- Proper cleanup in
dispose()method
-
"NFC is not available":
- Check if NFC is enabled in device settings
- Ensure you're testing on a physical device (not emulator)
- Verify your device has NFC hardware
-
"Error reading tag":
- Ensure the tag is close enough to the device
- Try holding the tag steady for a few seconds
- Some tags may not support NDEF format
-
"NFC is not available" (Most Common Issue):
Root Cause: Missing NFC capability or entitlements configuration in Xcode.
Solution:
- Open
ios/Runner.xcworkspacein Xcode - Select Runner target → "Signing & Capabilities" tab
- Add "Near Field Communication Tag Reading" capability
- Verify
Runner/Runner.entitlementsis linked in "Code Signing Entitlements" - Clean build folder: Product → Clean Build Folder (⇧⌘K)
- Rebuild:
flutter clean && flutter pub get && flutter run
Verification Steps:
- Check that
Runner.entitlementsexists inios/Runner/ - Verify it contains
com.apple.developer.nfc.readersession.formats - Ensure Info.plist has
NFCReaderUsageDescription - Confirm the capability appears in Xcode's "Signing & Capabilities" tab
- Open
-
"NFC is not available" on iPhone 13 Pro or other supported devices:
- This is always a configuration issue, not a hardware issue
- iPhone 7 and later models support NFC
- The problem is missing Xcode capability setup (see above)
-
Build errors:
- Clean and rebuild:
flutter clean && flutter pub get - Reinstall pods:
cd ios && rm -rf Pods Podfile.lock && pod install && cd .. - Ensure Xcode has the NFC capability enabled
- Check that minimum iOS version is 11.0+ (your project uses 13.0+)
- Clean and rebuild:
-
Entitlements not found error:
- Verify
Runner.entitlementsfile exists atios/Runner/Runner.entitlements - Check that it's added to the Xcode project (should appear in file navigator)
- Ensure "Code Signing Entitlements" build setting points to
Runner/Runner.entitlements
- Verify
flutter_nfc_kit: ^5.0.0- NFC functionality for Flutter
This project is a Flutter application template.
- NFC operations require physical devices - emulators/simulators do not support NFC
- Some NFC tags may be read-only and cannot be written to
- The app uses a 30-second timeout for NFC operations
- NDEF URL records use the standard format with prefix codes (0x04 for https://)