Skip to content
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

fix: inlineimagecontroller now has a validation check #1123

Open
wants to merge 1 commit into
base: flutter_app
Choose a base branch
from

Conversation

ARYPROGRAMMER
Copy link

@ARYPROGRAMMER ARYPROGRAMMER commented Dec 26, 2024

This PR solves a small edge case where the Value of inlineimagecontroller used by ExtendedTextField is null. Ideally it should have some sort of error checking mechanism else when it gets saved and is played from the SavedBadges section, it throws the error:

======== Exception caught by gesture ===============================================================
The following ArgumentError was thrown while handling a gesture:
Invalid argument(s): Invalid hex string:

When the exception was thrown, this was the stack: 
#0      hexStringToBool (package:badgemagic/bademagic_module/utils/byte_array_utils.dart:35:5)
#1      SavedBadgeProvider.savedBadgeAnimation (package:badgemagic/providers/saved_badge_provider.dart:101:36)
#2      SaveBadgeCard.build.<anonymous closure>.<anonymous closure> (package:badgemagic/view/widgets/save_badge_card.dart:84:34)
#3      _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1170:21)
#4      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:351:24)
#5      TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:656:11)
#6      BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:313:5)
#7      BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:283:7)
#8      GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:169:27)
#9      GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:505:20)
#10     GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:481:22)
#11     RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:450:11)
#12     GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:426:7)
#13     GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:389:5)
#14     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:336:7)
#15     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:305:9)
#16     _invoke1 (dart:ui/hooks.dart:328:13)
#17     PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:442:7)
#18     _dispatchPointerDataPacket (dart:ui/hooks.dart:262:31)
Handler: "onTap"
Recognizer: TapGestureRecognizer#5a747
  debugOwner: GestureDetector
  state: ready
  won arena
  finalPosition: Offset(140.7, 397.5)
  finalLocalPosition: Offset(5.7, 16.7)
  button: 1
  sent tap down

THE CHANGES IN THIS PR FIX THIS

Summary by Sourcery

Bug Fixes:

  • Fixed an issue where saving a badge with an empty inline image value would throw an error.

Copy link

sourcery-ai bot commented Dec 26, 2024

Reviewer's Guide by Sourcery

This PR introduces a validation check for the inlineimagecontroller to prevent a runtime error when the value is null. A user-facing error message is now displayed if the controller value is empty, guiding the user to input a valid value before saving.

Sequence diagram for save badge validation flow

sequenceDiagram
    actor User
    participant UI as HomeScreen
    participant Controller as InlineImageController
    participant Dialog as SaveBadgeDialog

    User->>UI: Clicks Save Button
    UI->>Controller: Check text value
    alt text is empty
        Controller-->>UI: Empty value
        UI->>UI: Set error message
        UI-->>User: Display error hint
    else text has value
        Controller-->>UI: Valid value
        UI->>UI: Clear error message
        UI->>Dialog: Show save dialog
        Dialog-->>User: Display save options
    end
Loading

State diagram for inline image controller validation

stateDiagram-v2
    [*] --> Empty
    Empty --> Error: Save clicked
    Error --> Valid: Text entered
    Valid --> SaveDialog: Save clicked
    SaveDialog --> [*]

    note right of Empty: Initial state
    note right of Error: Shows red error message
    note right of Valid: Ready to save
Loading

File-Level Changes

Change Details Files
Added validation for the inlineimagecontroller
  • A validation check is added to the onTap callback of the save button. If inlineimagecontroller.text is empty, an error message is displayed. Otherwise, the existing save dialog logic is executed.
  • An error message is displayed using a hintText within the InputDecoration of the ExtendedTextField.
  • The errorVal variable is introduced to manage the error message state.
lib/view/homescreen.dart

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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 @ARYPROGRAMMER - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider implementing proper hex string validation instead of just checking for empty string to prevent invalid inputs from reaching hexStringToBool()
  • The error message could be more specific about the expected input format (e.g., 'Please enter a valid hex string')
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 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.

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.

1 participant