Home / projects / color merge

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

  1. 🎨 Merge Colors: Blend two colors to simulate stacking, producing a fully opaque result.

  2. βšͺ White Merge: Simplified method to merge a color with white.

  3. ⚫ 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.