Skip to content

feat: add flip functionality on final processed image#46

Merged
kienvo merged 12 commits intofossasia:mainfrom
Dhruv1797:main
Jun 9, 2025
Merged

feat: add flip functionality on final processed image#46
kienvo merged 12 commits intofossasia:mainfrom
Dhruv1797:main

Conversation

@Dhruv1797
Copy link
Copy Markdown
Contributor

@Dhruv1797 Dhruv1797 commented Jun 4, 2025

Fixes #35: added Flip (horizontal/vertical) for the final processed image to enhance output flexibility.

Previous UI: There was no option for the user to flip the final processed image.

WhatsApp Image 2025-06-04 at 10 49 30 PM (1)

Updated Ui: Now there are two button at bottom right corner that allows user to Flip (horzontal/vertical) the final processed image.

WhatsApp.Video.2025-06-04.at.10.49.54.PM.mp4

Summary by Sourcery

Introduce flip functionality for final processed images by adding UI controls and integrating flip transformations into the image processing workflow

New Features:

  • Add horizontal and vertical flip controls to the final processed image in the editor

Enhancements:

  • Extract image processing logic into a reusable processImages utility and convert ImageEditor to StatefulWidget to manage flip state

Build:

  • Bump intl dependency to ^0.20.2

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 4, 2025

Reviewer's Guide

This PR introduces horizontal and vertical flip functionality for the final processed image by converting the image editor to a stateful widget with flip toggles, extracting processing steps into a reusable utility, adding dedicated UI controls for flipping, and updating a dependency version.

Sequence Diagram for Image Flip Operation

sequenceDiagram
    actor User
    participant FC as FlipControls
    participant IES as _ImageEditorState
    participant IEU as ImageEditorUtils
    participant IL as ImageList

    User->>+FC: Taps 'Flip Horizontal'
    FC->>IES: onFlipHorizontal()
    activate IES
    IES->>IES: toggleFlipHorizontal()
    IES->>IES: setState({ flipHorizontal = !flipHorizontal })
    IES->>+IEU: processImages(originalImage, newFlipH, flipV, epd)
    IEU-->>-IES: List~img.Image~ (flipped)
    IES->>IL: Update with new images (during rebuild)
    IL-->>User: Displays horizontally flipped image
    deactivate IES
Loading

File-Level Changes

Change Details Files
Refactored ImageEditor to support flip state
  • Converted ImageEditor from StatelessWidget to StatefulWidget
  • Added flipHorizontal and flipVertical state variables
  • Implemented toggleFlipHorizontal and toggleFlipVertical methods
  • Updated build method to pass widget.epd and include flip flags in processing call
lib/view/image_editor.dart
Extracted image processing logic into utility
  • Created processImages function to resize, apply flips, and invoke epd methods
  • Replaced inline processing loop with call to processImages
lib/util/image_editor_utils.dart
Added FlipControls UI component
  • Introduced FlipControls widget with two FloatingActionButtons
  • Wired onFlipHorizontal and onFlipVertical callbacks
  • Positioned controls as floatingActionButton when an image is loaded
lib/view/widget/flip_controls.dart
lib/view/image_editor.dart
Updated dependency version
  • Bumped intl package from ^0.19.0 to ^0.20.2
pubspec.yaml

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!

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
Copy Markdown
Contributor

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

  • The flip controls are using the opposite asset filenames (the horizontal flip button shows the vertical icon and vice versa), please swap the asset paths.
  • Consider giving the flip buttons a visual “active” state (e.g. change color or icon) so users know when horizontal or vertical flipping is currently applied.
  • The intl version bump seems unrelated to this feature—please separate that dependency update into its own PR to keep the flip functionality focused.
Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: 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.

Comment on lines +25 to +28
child: Image.asset(
"assets/images/vertical_flip.png",
height: 24,
width: 24,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Horizontal flip button uses vertical flip asset

The flipH button should use the horizontal flip icon asset instead of the vertical_flip icon.

Suggested change
child: Image.asset(
"assets/images/vertical_flip.png",
height: 24,
width: 24,
child: Image.asset(
"assets/images/horizontal_flip.png",
height: 24,
width: 24,

Comment on lines +21 to +23
for (final method in epd.processingMethods) {
processedImgs.add(method(transformed));
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Clone transformed image per method to avoid side effects

Passing the same transformed image to all methods may lead to unintended side effects if any method mutates its input. Pass a copy of transformed to each method instead.

Suggested change
for (final method in epd.processingMethods) {
processedImgs.add(method(transformed));
}
for (final method in epd.processingMethods) {
processedImgs.add(method(img.copyResize(transformed)));
}

}
}
final List<img.Image> processedImgs = orgImg != null
? processImages(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (performance): Reprocessing on every build might hurt performance

Consider memoizing processImages results when its inputs (orgImg, flipHorizontal, flipVertical, epd) are unchanged to prevent unnecessary repeated processing.

@@ -0,0 +1,47 @@
import 'package:flutter/material.dart';

class FlipControls extends StatelessWidget {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: Add visual state feedback for flip controls

Pass the flip state to FlipControls and update the button style or icon color to reflect when a flip is active.

Suggested implementation:

class FlipControls extends StatelessWidget {
  final VoidCallback onFlipHorizontal;
  final VoidCallback onFlipVertical;
  final bool isFlippedHorizontally;
  final bool isFlippedVertically;

  const FlipControls({
    super.key,
    required this.onFlipHorizontal,
    required this.onFlipVertical,
    required this.isFlippedHorizontally,
    required this.isFlippedVertically,
  });

  @override
  Widget build(BuildContext context) {
    final Color activeColor = Theme.of(context).colorScheme.primary;
    final Color inactiveColor = Theme.of(context).iconTheme.color ?? Colors.black;

    return Padding(

You will also need to update the widget tree inside build to use the isFlippedHorizontally and isFlippedVertically booleans. For example, if you use IconButton for the flip controls, set the color property of the icon to activeColor when the corresponding flip is active, otherwise use inactiveColor.

Additionally, update all usages of FlipControls to pass the new required parameters: isFlippedHorizontally and isFlippedVertically.

Copy link
Copy Markdown
Contributor

@Vishveshwara Vishveshwara left a comment

Choose a reason for hiding this comment

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

@Dhruv1797 This looks good, well done!! @AsCress @kienvo can you guys review this as well?

@AsCress AsCress changed the title feat: added flip rotate functionality on final processed image. feat: added flip rotate functionality on final processed image Jun 5, 2025
Comment thread lib/view/widget/flip_controls.dart Outdated
@kienvo
Copy link
Copy Markdown
Member

kienvo commented Jun 5, 2025

Performance issue. Please avoid flipping every image. Instead, use Transform.flip to flip the view, then use Image.flip** to flip the selected image at the transfer event.

@Dhruv1797
Copy link
Copy Markdown
Contributor Author

Performance issue. Please avoid flipping every image. Instead, use Transform.flip to flip the view, then use Image.flip** to flip the selected image at the transfer event.

@kienvo Nice catch, Thank you, i have made this change now using use Transform.flip instead of flipping every image and only fliping the selected one at the transfer event. please review it once.

@kienvo
Copy link
Copy Markdown
Member

kienvo commented Jun 5, 2025

Looks good! There is one thing left: assets/images/h-flip.png and assets/images/v-flip.png don't look the same. One has sharp corners, the other has round corners. My suggestion is to rotate assets/images/h-flip.png for the v-flip symbol.

@Dhruv1797
Copy link
Copy Markdown
Contributor Author

Looks good! There is one thing left: assets/images/h-flip.png and assets/images/v-flip.png don't look the same. One has sharp corners, the other has round corners. My suggestion is to rotate assets/images/h-flip.png for the v-flip symbol.

Thanks @Kinevo, yeah sure, this is done. I’ve rotated assets/images/h-flip.png for the vertical flip icon to keep the style consistent. Please review it once.

Copy link
Copy Markdown
Member

@kienvo kienvo left a comment

Choose a reason for hiding this comment

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

lgtm

@kienvo kienvo changed the title feat: added flip rotate functionality on final processed image feat: add flip functionality on final processed image Jun 9, 2025
@kienvo kienvo merged commit 3bcd2d3 into fossasia:main Jun 9, 2025
3 checks passed
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.

4 participants