-
Notifications
You must be signed in to change notification settings - Fork 9
fix: open nfc settings when switched off #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's Guide by SourceryThis pull request implements NFC availability checks and provides user guidance, including prompting the user to enable NFC and redirecting them to the appropriate settings on both Android and iOS platforms. It uses FlutterNfcKit for NFC checks and platform-specific methods for opening settings. Sequence diagram for handling NFC availabilitysequenceDiagram
participant User
participant Flutter App
participant FlutterNfcKit
participant Platform (Android/iOS)
User->>Flutter App: Triggers NFC action (e.g., writeImages)
Flutter App->>FlutterNfcKit: Check NFC availability
FlutterNfcKit->>Platform: Get NFC status
Platform-->>FlutterNfcKit: Returns NFC status (available, disabled, not_supported)
FlutterNfcKit-->>Flutter App: Returns NFC availability
alt NFC is disabled
Flutter App->>Flutter App: Show toast message "NFC is disabled. Please enable it."
alt Platform is Android
Flutter App->>Platform: Open NFC settings
else Platform is iOS
Flutter App->>Platform: Open App settings
end
else NFC is not supported
Flutter App->>Flutter App: Show toast message "This device does not support NFC."
else NFC is available
Flutter App->>Flutter App: Show toast message "Bring your phone near to the Magic Epaper Hardware"
Flutter App->>FlutterNfcKit: poll(timeout)
FlutterNfcKit->>Platform: Poll for NFC tag
Platform-->>FlutterNfcKit: Returns NFC tag
FlutterNfcKit-->>Flutter App: Returns NFC tag
end
Updated class diagram for NFCSettingsLauncherclassDiagram
class NFCSettingsLauncher {
+static const platform
+static Future<void> openNFCSettings()
}
note for NFCSettingsLauncher "Utility class to open NFC settings on Android and iOS"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Dhruv1797 - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding error handling around the
AppSettings.openAppSettings()
call for iOS, as it can fail if the user has restricted app settings access. - The
CHANNEL
constant inMainActivity.kt
should be defined in a more central place (e.g. a shared constants file) to avoid potential mismatches.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
if (call.method == "openNFCSettings") { | ||
val intent = Intent(Settings.ACTION_NFC_SETTINGS) | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
startActivity(intent) | ||
result.success(null) | ||
} else { | ||
result.notImplemented() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Consider error handling for the platform intent.
In case startActivity fails (for example, if NFC settings are not available), adding try/catch around the intent launch could help avoid unexpected crashes.
if (call.method == "openNFCSettings") { | |
val intent = Intent(Settings.ACTION_NFC_SETTINGS) | |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | |
startActivity(intent) | |
result.success(null) | |
} else { | |
result.notImplemented() | |
} | |
if (call.method == "openNFCSettings") { | |
try { | |
val intent = Intent(Settings.ACTION_NFC_SETTINGS) | |
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | |
startActivity(intent) | |
result.success(null) | |
} catch (e: Exception) { | |
result.error("UNAVAILABLE", "NFC Settings not available", null) | |
} | |
} else { | |
result.notImplemented() | |
} |
@kienvo please review it once. |
nfc-handing-demo.mp4Here is the demo video for nfc-handling for opening nfc settings-when nfc is disabled or off. |
The common build failed. Please resolve it. |
Hi @kienvo, |
Hi @kienvo, The common build and Android build have passed successfully. The only issue remaining is with the iOS build. According to the logs, CocoaPods is reporting a compatibility issue for the pod "flutter_nfc_kit", which is the same as before—I haven’t made any changes to it. Should i update this dependency and push changes: |
What’s implemented:
Files Modified:
Summary by Sourcery
Improve NFC handling by adding comprehensive NFC availability checks, user notifications, and platform-specific settings navigation
New Features:
Bug Fixes:
Enhancements: