Skip to content

Comments

Just an idea for improved color handling#62

Open
rpock wants to merge 1 commit intokekland:masterfrom
rpock:idea-cupert-color-adapt
Open

Just an idea for improved color handling#62
rpock wants to merge 1 commit intokekland:masterfrom
rpock:idea-cupert-color-adapt

Conversation

@rpock
Copy link

@rpock rpock commented May 28, 2025

Improved color handling in Croppy widget

This is a quick suggestion for improving color handling in the Croppy widget, especially for Cupertino components in light mode.

Key changes:

  • Added overlayColor parameter to enable theme-based colors for the crop area overlay
  • Modified the overlay outside the crop area to use scaffoldBackgroundColor with 98% opacity instead of always being dark
  • Replaced hardcoded colors in Cupertino components with theme-based alternatives
  • Added color parameters to various components to enable better theming

image image

Here is an example in light mode before the changes

image

This implementation is just meant as a suggestion since I needed these features for a personal project. The code was implemented quickly and might not be as clean or optimized as it could be, but perhaps it can serve as inspiration for proper implementation.

The changes allow the widget to better adapt to different themes, particularly in light mode where the previous dark overlay didn't work well.

Thank you for creating this excellent package - it's very helpful for my current project and will be valuable for future projects too! 🙏

Detailed Changes

lib/src/model/croppable_image_data.dart:

  • Added overlayColor parameter to copyWith() method to properly preserve theme colors

lib/src/widgets/common/croppable_image_widget.dart:

  • Replaced hardcoded black overlay with theme-based overlay color (98% opacity)
  • Unified fallback colors for consistent appearance in light/dark mode
  • Changed blend mode to srcOver for better visibility

lib/src/pages/cupertino_pages.dart:

  • Increased overlay opacity to 98% for stronger darkening effect
  • Added theme color extraction from scaffoldBackgroundColor

lib/src/pages/material_pages.dart:

  • Set consistent 98% overlay opacity
  • Added theme color extraction from scaffoldBackgroundColor

lib/src/widgets/cupertino/default_cupertino_croppable_image_controller.dart:

  • Added overlayColor propagation when reusing initialData
  • Fixed data inheritance to maintain theme colors

lib/src/widgets/material/default_material_croppable_image_controller.dart:

  • Added overlayColor propagation when reusing initialData
  • Fixed data inheritance to maintain theme colors

lib/src/widgets/cupertino/toolbar/cupertino_knob.dart:

  • Implemented three-state color logic (positive, neutral, negative)
  • Added semi-transparent background with scaffoldBackgroundColor (50% opacity)
  • Used primaryColor for positive values and primaryContrastingColor for neutral/negative

lib/src/widgets/cupertino/toolbar/cupertino_image_transformation_toolbar.dart:

  • Applied theme-based colors to all sliders (active/inactive states)
  • Used primaryColor for active state and textStyle color for inactive state

lib/src/widgets/cupertino/handles/cupertino_image_crop_handles.dart:

  • Applied theme colors to handles and guide lines
  • Used primaryColor and primaryContrastingColor instead of hardcoded colors

lib/src/widgets/cupertino/toolbar/cupertino_rotation_slider.dart:

  • Added color parameters for different states
  • Used theme colors for better visibility and state indication
  • Applied consistent color scheme with other UI elements

lib/src/widgets/cupertino/toolbar/cupertino_image_aspect_ratio_toolbar.dart:

  • Applied theme-based colors for better visibility and consistency
  • Improved active/inactive state indication
  • Aligned with overall UI color scheme

lib/src/widgets/cupertino/theme/cupertino_image_cropper_theme.dart:

  • Integrated theme-based color handling
  • Improved compatibility with light/dark mode
  • Applied consistent color variables throughout theme

lib/src/widgets/cupertino/icons/*:

  • Applied uniform theme colors across all icons
  • Used primaryContrastingColor for consistent appearance
  • Improved visibility in both light and dark modes

lib/src/widgets/cupertino/cupertino_image_cropper_app_bar.dart:

  • Optimized color scheme for app bar icons
  • Applied theme colors for better visibility
  • Aligned with bottom app bar styling

lib/src/widgets/cupertino/cupertino_image_cropper_bottom_app_bar.dart:

  • Improved color handling for bottom bar elements
  • Ensured consistency with the rest of the UI
  • Applied theme-based colors for buttons and icons

# Improved color handling in Croppy widget

This is a quick suggestion for improving color handling in the Croppy widget, especially for Cupertino components in light mode.

## Key changes:
- Added overlayColor parameter to enable theme-based colors for the crop area overlay
- Modified the overlay outside the crop area to use scaffoldBackgroundColor with 98% opacity instead of always being dark
- Replaced hardcoded colors in Cupertino components with theme-based alternatives
- Added color parameters to various components to enable better theming

This implementation is just meant as a suggestion since I needed these features for a personal project. The code was implemented quickly and might not be as clean or optimized as it could be, but perhaps it can serve as inspiration for proper implementation.

The changes allow the widget to better adapt to different themes, particularly in light mode where the previous dark overlay didn't work well.

### Thank you for creating this excellent package - it's been very helpful in my projects! 🙏

## Detailed Changes

### lib/src/model/croppable_image_data.dart:
- Added overlayColor parameter to copyWith() method to properly preserve theme colors

### lib/src/widgets/common/croppable_image_widget.dart:
- Replaced hardcoded black overlay with theme-based overlay color (98% opacity)
- Unified fallback colors for consistent appearance in light/dark mode
- Changed blend mode to srcOver for better visibility

### lib/src/pages/cupertino_pages.dart:
- Increased overlay opacity to 98% for stronger darkening effect
- Added theme color extraction from scaffoldBackgroundColor

### lib/src/pages/material_pages.dart:
- Set consistent 98% overlay opacity
- Added theme color extraction from scaffoldBackgroundColor

### lib/src/widgets/cupertino/default_cupertino_croppable_image_controller.dart:
- Added overlayColor propagation when reusing initialData
- Fixed data inheritance to maintain theme colors

### lib/src/widgets/material/default_material_croppable_image_controller.dart:
- Added overlayColor propagation when reusing initialData
- Fixed data inheritance to maintain theme colors

### lib/src/widgets/cupertino/toolbar/cupertino_knob.dart:
- Implemented three-state color logic (positive, neutral, negative)
- Added semi-transparent background with scaffoldBackgroundColor (50% opacity)
- Used primaryColor for positive values and primaryContrastingColor for neutral/negative

### lib/src/widgets/cupertino/toolbar/cupertino_image_transformation_toolbar.dart:
- Applied theme-based colors to all sliders (active/inactive states)
- Used primaryColor for active state and textStyle color for inactive state
- Improved formatting for better readability

### lib/src/widgets/cupertino/handles/cupertino_image_crop_handles.dart:
- Applied theme colors to handles and guide lines
- Used primaryColor and primaryContrastingColor instead of hardcoded colors
- Improved formatting and alignment

### lib/src/widgets/cupertino/toolbar/cupertino_rotation_slider.dart:
- Added color parameters for different states
- Used theme colors for better visibility and state indication
- Applied consistent color scheme with other UI elements

### lib/src/widgets/cupertino/toolbar/cupertino_image_aspect_ratio_toolbar.dart:
- Applied theme-based colors for better visibility and consistency
- Improved active/inactive state indication
- Aligned with overall UI color scheme

### lib/src/widgets/cupertino/theme/cupertino_image_cropper_theme.dart:
- Integrated theme-based color handling
- Improved compatibility with light/dark mode
- Applied consistent color variables throughout theme

### lib/src/widgets/cupertino/icons/*:
- Applied uniform theme colors across all icons
- Used primaryContrastingColor for consistent appearance
- Improved visibility in both light and dark modes

### lib/src/widgets/cupertino/cupertino_image_cropper_app_bar.dart:
- Optimized color scheme for app bar icons
- Applied theme colors for better visibility
- Aligned with bottom app bar styling

### lib/src/widgets/cupertino/cupertino_image_cropper_bottom_app_bar.dart:
- Improved color handling for bottom bar elements
- Ensured consistency with the rest of the UI
- Applied theme-based colors for buttons and icons
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