logo

Hcody

Home/ Projects / color-merge

Project: Color Merge

Color Merge - Flutter Color Blending Utilities

By Hisham · Published on November 28, 2024

Intro

A lightweight Flutter package for blending colors seamlessly, simulating stacking effects, and providing white/black merge helpers.

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.

🎨 Merge Colors

Blend two colors to simulate stacking, producing a fully opaque result.

⚪ White Merge

A simplified method to quickly blend any color with white.

⚫ Black Merge

A simplified method to quickly blend any color with black.

Quick Start

// Standard merge
final result = Colors.purple.withOpacity(0.5).merge(Colors.white);

// Shortcuts
final whiteBg = Colors.green.withOpacity(0.3).whiteMerge();
final darkBg = Colors.blue.withOpacity(0.4).blackMerge();
The 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.
  • Complexity in maintaining dynamic themes when specific background blends are required.
The Solutions

Color Merge introduces the Color.merge() extension, allowing you to simulate complex stacking in a single line of code. By providing shortcuts like whiteMerge(), it reduces boilerplate and makes UI code significantly cleaner.