Skip to content

fix: create color palette based on display's supported colors#40

Merged
AsCress merged 7 commits intofossasia:mainfrom
Vishveshwara:color_fix
Jun 3, 2025
Merged

fix: create color palette based on display's supported colors#40
AsCress merged 7 commits intofossasia:mainfrom
Vishveshwara:color_fix

Conversation

@Vishveshwara
Copy link
Copy Markdown
Contributor

@Vishveshwara Vishveshwara commented May 31, 2025

Fixes #38

Screen Recording:

Color.palette.fix.mp4
  • Used a provider to use the palette displayed in the epd class
  • changed initialisation color for painting from red to black

Summary by Sourcery

Introduce and wire up ColorPaletteProvider to dynamically feed display-specific color palettes into the color picker and default the initial paint color to black.

New Features:

  • Introduce ColorPaletteProvider to manage and update the active color palette based on the selected display.

Bug Fixes:

  • Change the default initial paint color from red to black across editors.

Enhancements:

  • Wire up DisplaySelectionScreen to populate the provider with the chosen e-paper display’s supported colors.
  • Refactor ColorPickerCustom and BottomBarCustom to consume the dynamic palette from the provider and remove hard-coded initialColor parameters.
  • Register ColorPaletteProvider in the app’s MultiProvider setup.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 31, 2025

Reviewer's Guide

This PR introduces a ChangeNotifier-based ColorPaletteProvider to manage and propagate display-specific color palettes, registers it in the app root, updates it when a display is selected, uses it in the ColorPicker widget, and standardizes the initial paint color to black by removing explicit initColor parameters across several editor components.

File-Level Changes

Change Details Files
Add ColorPaletteProvider and register it in the app root
  • Created ColorPaletteProvider with colors list and updateColors()
  • Registered ChangeNotifierProvider for ColorPaletteProvider in main.dart
  • Imported provider and ColorPaletteProvider in main.dart
lib/provider/color_palette_provider.dart
lib/main.dart
Integrate provider into ColorPickerCustom to use dynamic palettes
  • Removed initColor parameter and defaulted initial color to black
  • Replaced hardcoded color list with context.watch().colors
  • Initialized _selectedColor from provider in initState
lib/pro_image_editor/features/color_picker.dart
Update DisplaySelectionScreen to set the current palette on selection
  • Invoked context.read().updateColors(...) when a display is chosen
  • Imported provider and ColorPaletteProvider in display_selection_screen.dart
lib/view/display_selection_screen.dart
Standardize initial paint color and remove redundant initColor props
  • Eliminated initColor parameters and fields in BottomBarCustom and ColorPickerCustom
  • Defaulted initialColor to Colors.black in PaintEditorStyle
  • Removed passing of initColor in movable_background_image and text_bottom_bar setups
lib/pro_image_editor/features/bottom_bar.dart
lib/pro_image_editor/features/movable_background_image.dart
lib/pro_image_editor/features/text_bottom_bar.dart

Assessment against linked issues

Issue Objective Addressed Explanation
#38 Remove red color from the color palette when using a black and white e-ink display.

Possibly linked issues


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

  • You’ve declared _selectedColor as late but never initialize it—consider setting it in initState (e.g., to the first palette color or a default) to avoid runtime errors.
  • Reassigning _colors directly in build() on every frame can cause unnecessary rebuilds; consider fetching the provider palette once (e.g., in initState) or using Selector to limit rebuild scope.
  • The initColor property in BottomBarCustom is no longer used—remove it from the constructor and class to clean up the API.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 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 thread lib/main.dart Outdated
void main() {
runApp(MultiProvider(providers: [
ChangeNotifierProvider(create: (context) => ImageLoader()),
ChangeNotifierProvider(create: (context) => ColorPaletteProvider()),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need to add this as a ChangeNotiferProvider for the whole app if we're using this only in a certain screen ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey @AsCress , i am planning to add color channel adjustments, to control red , black , white threshold , so this provider should work for image_editor.dart as well, where i am planning to add it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Vishveshwara Then maybe inject it using getIt ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

okay , I will try using getIt and update this pr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have implemented it using getIt below, since i am updating the colors of the ColorPaletteProvider in only the display_selection_screen , what is the actual benifit using getIt ? since provider can do the same function, can you please explain this

@Vishveshwara Vishveshwara requested a review from AsCress June 2, 2025 11:21
Comment thread lib/main.dart Outdated
setupLocator();
runApp(MultiProvider(providers: [
ChangeNotifierProvider(create: (context) => ImageLoader()),
ChangeNotifierProvider<ColorPaletteProvider>(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Vishveshwara Nicely implemented getIt! Good job on that ! However, the whole purpose of using getIt is that you can inject that particular dependency wherever you want, while still maintaining a single instance of it in your app. We don't unleash it's potential if we just inject it in the beginning for the whole app, this is similar to what you were doing before.
Just inject it wherever required. Let's say you want to use it as a ChangeNotifierProvider for display_selection_screen.dart and image_editor.dart, register that ChangeNotifierProvider using MultiProvider for those screens only, and fetch it using getIt.
I'll make myself more clear here, wrap those both screens with this:
MultiProvider(providers: [ChangeNotifierProvider<ColorPaletteProvider>( create: (context) => getIt<ColorPaletteProvider>()) ,], child: ... ));
instead of wrapping the whole MyApp() function with it.
Let me know if you still didn't understand anything here !

Copy link
Copy Markdown
Contributor Author

@Vishveshwara Vishveshwara Jun 3, 2025

Choose a reason for hiding this comment

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

Hey @AsCress thanks for the explanation , I understand it , let me try implementing it first if I run into any issues i will mention you.

@AsCress
Copy link
Copy Markdown
Collaborator

AsCress commented Jun 2, 2025

If you were using the dependency only for one screen, then you could also simply create a new instance of your provider for that screen only (since it is something required only for that screen and not the whole app), without using getIt. However, you mentioned that you're gonna use your provider in multiple screens, then getIt provides a nice way to handle that.

…of main.dart and used getit to get the colors in color_picker.dart
@Vishveshwara
Copy link
Copy Markdown
Contributor Author

@AsCress i have used

return ChangeNotifierProvider<ColorPaletteProvider>(
        create: (_) => getIt<ColorPaletteProvider>(),
        builder: (context, child) {

since i was getting an error with the method you had suggested and

I have used the below code to update the colors in color_picker.dart

final List<Color> _colors = getIt<ColorPaletteProvider>().colors;

Is this fine?

@AsCress AsCress changed the title fix: Creates Color palette based on display's supported colours fix: create color palette based on display's supported colors Jun 3, 2025
Copy link
Copy Markdown
Collaborator

@AsCress AsCress left a comment

Choose a reason for hiding this comment

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

@Vishveshwara Nicely implemented !

@AsCress AsCress merged commit 571ed9b into fossasia:main Jun 3, 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.

Palette colors should be changed according to the display

2 participants