fix: create color palette based on display's supported colors#40
fix: create color palette based on display's supported colors#40AsCress merged 7 commits intofossasia:mainfrom
Conversation
Reviewer's GuideThis 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
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @Vishveshwara - I've reviewed your changes - here's some feedback:
- You’ve declared
_selectedColoras late but never initialize it—consider setting it ininitState(e.g., to the first palette color or a default) to avoid runtime errors. - Reassigning
_colorsdirectly inbuild()on every frame can cause unnecessary rebuilds; consider fetching the provider palette once (e.g., ininitState) or usingSelectorto limit rebuild scope. - The
initColorproperty inBottomBarCustomis 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
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| void main() { | ||
| runApp(MultiProvider(providers: [ | ||
| ChangeNotifierProvider(create: (context) => ImageLoader()), | ||
| ChangeNotifierProvider(create: (context) => ColorPaletteProvider()), |
There was a problem hiding this comment.
Do we need to add this as a ChangeNotiferProvider for the whole app if we're using this only in a certain screen ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@Vishveshwara Then maybe inject it using getIt ?
There was a problem hiding this comment.
okay , I will try using getIt and update this pr
There was a problem hiding this comment.
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
| setupLocator(); | ||
| runApp(MultiProvider(providers: [ | ||
| ChangeNotifierProvider(create: (context) => ImageLoader()), | ||
| ChangeNotifierProvider<ColorPaletteProvider>( |
There was a problem hiding this comment.
@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 !
There was a problem hiding this comment.
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.
|
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 |
…of main.dart and used getit to get the colors in color_picker.dart
|
@AsCress i have used 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
Is this fine? |
AsCress
left a comment
There was a problem hiding this comment.
@Vishveshwara Nicely implemented !
Fixes #38
Screen Recording:
Color.palette.fix.mp4
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:
Bug Fixes:
Enhancements: