Skip to content

Fix nfc #14

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Fix nfc #14

wants to merge 2 commits into from

Conversation

Yugesh-Kumar-S
Copy link

@Yugesh-Kumar-S Yugesh-Kumar-S commented Mar 29, 2025

Closes #7

Added a notification to turn on the NFC if disabled .

Summary by Sourcery

Improve NFC functionality by adding device and NFC availability checks, error handling, and user feedback

New Features:

  • Add NFC availability and device support checks before initiating NFC transfer

Bug Fixes:

  • Prevent NFC transfer attempts on unsupported or disabled devices

Enhancements:

  • Implement error handling and user feedback mechanisms for NFC operations

Copy link

sourcery-ai bot commented Mar 29, 2025

Reviewer's Guide by Sourcery

This pull request adds NFC availability checks and notifications to the application. It ensures that the user is informed if NFC is not supported or disabled, and provides feedback on the transfer process. It also adds the fluttertoast and flutter_nfc_kit packages as dependencies.

Sequence diagram for NFC write operation

sequenceDiagram
    participant User
    participant MyHomePage
    participant FlutterNfcKit
    participant MagicEpd
    participant FlutterToast

    User->>MyHomePage: Presses 'Start transfer' button
    MyHomePage->>FlutterNfcKit: Check NFC availability
    alt NFC not supported
        FlutterNfcKit-->>MyHomePage: NFCAvailability.not_supported
        MyHomePage->>MyHomePage: _showDialog('NFC not supported')
        MyHomePage->>User: Show dialog
    else NFC disabled
        FlutterNfcKit-->>MyHomePage: NFCAvailability.disabled
        MyHomePage->>MyHomePage: _showDialog('NFC is turned off')
        MyHomePage->>User: Show dialog
    else NFC available
        FlutterNfcKit-->>MyHomePage: NFCAvailability.available
        MyHomePage->>ImageHandler: Load image
        ImageHandler-->>MyHomePage: (red, black) image data
        MyHomePage->>MagicEpd: writeChunk(blackChunks, redChunks)
        MagicEpd-->>MyHomePage:  
        MyHomePage->>FlutterToast: _showToast('Transfer started successfully!')
        FlutterToast->>User: Show toast
    end
Loading

File-Level Changes

Change Details Files
Added NFC availability checks and notifications.
  • Implemented checks for NFC support and enabled status.
  • Displayed a dialog if NFC is not supported.
  • Displayed a dialog if NFC is disabled, prompting the user to enable it.
  • Added a toast notification to indicate the transfer started successfully.
  • Wrapped the NFC writing process in a try-catch block to handle potential errors and display an error dialog.
lib/main.dart
Added the fluttertoast and flutter_nfc_kit packages.
  • Added fluttertoast as a dependency.
  • Added flutter_nfc_kit as a dependency.
pubspec.yaml
Modified the nfc_write function to accept BuildContext.
  • The nfc_write function now requires a BuildContext parameter.
  • The nfc_write function now uses the BuildContext to display dialogs.
lib/main.dart
Added helper functions to display dialogs and toasts.
  • Added a _showDialog function to display AlertDialogs.
  • Added a _showToast function to display toast notifications.
lib/main.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#7 The nfc_write() function should correctly execute the NFC write process and confirm the transfer.
#7 Resolve the error: PlatformException(404, NFC not available, null, null).
#7 The terminal should not log an array of [255, 255, 255, ...] instead of expected data.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Yugesh-Kumar-S - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider extracting the NFC functionality into a separate class or service to improve code organization and testability.
  • The toast message should be more descriptive, such as 'Transfer started successfully, tap the NFC tag'.
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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -61,7 +116,7 @@ class MyHomePage extends StatelessWidget {
ElevatedButton(
onPressed: () {
print('button pressed!');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Remove or replace the debug print statement.

Debug prints can clutter production logs. If logging is necessary, consider using a proper logging framework or conditionally compiling debug statements.

@kienvo
Copy link
Member

kienvo commented Apr 2, 2025

This looks good but would be nicer if it had some way to navigate to the NFC setting so users won't have to go find the NFC setting on their phone.

Copy link
Member

@mariobehling mariobehling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve conflicts and add option into the settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NFC Write Function Returns Unexpected Random Numbers
3 participants