Project: Color Merge
Color Merge - Flutter Color Blending Utilities
By Hisham Β· Published on November 28, 2024
Description
Color Merge is a lightweight Flutter package that provides utilities for merging colors seamlessly.
It allows developers to simulate the effect of stacking colors on top of one another, ignoring opacity, and adapt colors dynamically based on the app's theme.
β¨ Features
π¨ Merge Colors: Blend two colors to simulate stacking, producing a fully opaque result.
βͺ White Merge: Simplified method to merge a color with white.
β« Black Merge: Simplified method to merge a color with black.
π Installation
Add color_merge
to your pubspec.yaml
:
dependencies:
color_merge: ^1.0.0
Run:
flutter pub get
π οΈ Usage
π Merge Two Colors
final result = Colors.purple.withOpacity(0.5).merge(Colors.white);
βͺ White Merge
final merged = Colors.green.withOpacity(0.3).whiteMerge();
β« Black Merge
final merged = Colors.green.withOpacity(0.3).blackMerge();
π Methods
Color.merge(Color otherColor):
Blends the current color with another, producing a fully opaque color.
final baseColor = Colors.white;
final overlay = Colors.red.withOpacity(0.5);
final result = overlay.merge(baseColor);
Challenges
β Default Flutter widgets donβt provide a direct way to blend two colors without adding multiple containers.
β Achieving a stacked opacity effect often leads to extra nesting and less readable code.
β Developers needed a clean and reusable approach for blending colors.
Solutions
β Introduced Color.merge() to simulate color stacking in a single line.
β Added shortcuts: whiteMerge() and blackMerge() for common use cases.
β Delivered a lightweight and intuitive API that reduces boilerplate.