Search packages, repositories and app categories

Package detailsv3.0.0

color

A simple Dart package exposing a Color class which can be used to create, convert, alter, and compare colors in a variety of colorspaces.

AndroidiOSWebmacOSWindowsLinux
30-day downloads
829K
Likes
36
Pub points
130

Install package

flutter pub add color

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The color package is a lightweight Dart library that provides a comprehensive Color class for creating, manipulating, and comparing colors across multiple color spaces. It supports operations like color conversion, blending, and comparison, making it ideal for applications requiring precise color handling. Designed for simplicity and performance, it integrates seamlessly into Flutter projects on all major platforms. The package is particularly useful in design tools, theme systems, and visual applications where accurate color management is essential.

Use cases

  • Theme customization
  • Color palette generation
  • Visual design tools
  • Image processing
  • UI prototyping
  • Cross-platform color consistency

Key features

  • Supports multiple color spaces
  • Color conversion utilities
  • Color comparison methods
  • Easy-to-use API
  • Platform-agnostic
  • Extensible color operations

Suitable for

  • Flutter developers
  • Design system creators
  • UI/UX designers
  • Color-sensitive applications
  • Cross-platform apps
  • Prototyping tools

Considerations

  • Limited to basic color operations
  • No built-in color picker UI
  • Requires manual color space management
  • Not optimized for complex image analysis
  • Minimal documentation beyond code comments
  • No runtime color validation

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Color

A simple Dart package exposing a Color class which can be used to create, convert, and compare colors.

Installation

  1. Add this to your package's pubspec.yaml file:
dependencies:
  color: any
  1. Get the package using your IDE's GUI or via command line with
$ pub get
  1. Import the color.dart file in your app
import 'package:color/color.dart';

Usage

Color objects can be constructed using any of a few available constructors.

To create a color from rgb values, call

Color rgbColor = new Color.rgb(192, 255, 238);
RgbColor rgbColor = new RgbColor(192, 255, 238);

Alternatively, a color can be created directly in a number of other color spaces.

RgbColor rgb = new RgbColor(192, 255, 238);
HexColor hex = new HexColor('c0ffee');
HslColor hsl = new HslColor(163.8, 100, 87.6);
XyzColor xyz = new XyzColor(72.931, 88.9, 94.204);
CielabColor cielab = new CielabColor(95.538, -23.02, 1.732);

Colors are immutable, and can be created using const constructors.

RgbColor rgb = const RgbColor(192, 255, 238);

Colors can be created directly from CSS3 color names.

RgbColor black = new RgbColor.name('black'); //factory constructor that returns a const RgbColor
RgbColor white = RgbColor.namedColors['black']; //directly reference the const RgbColor without the factory

Colors implementing the CssColorSpace interface can output a css string representation.

RgbColor rgb = new RgbColor(192, 255, 238);
HexColor hex = new HexColor('c0ffee');
HslColor hsl = new HslColor(163.8, 100, 87.6);
assert(rgb is CssColorSpace, true);
assert(hex is CssColorSpace, true);
assert(hsl is CssColorSpace, true);
print(rgb.toCssString()); //rgb(192, 255, 238)
print(hex.toCssString()); //#c0ffee
print(hsl.toCssString()); //hsl(163.8, 100.0%, 87.6%)

Colors can be compared using the == operator, which will evaluate to true if the two colors share identical rgb values after being rounded to integers.

assert(new Color.hex('c0ffee') == new Color.hex('c0ffee'));
assert(new Color.rgb('192, 255, 238') == new Color.hex('c0ffee'));

Colors can be converted from one color space to another by calling the appropriate toXXXColor method on them.

HslColor hsl = new RgbColor(192, 255, 238).toHslColor();

Colors can be altered using a ColorFilter, which will return a new color in the same color space as the input color with that filter applied to it.

RgbColor grey = ColorFilter.greyscale(new RgbColor(192, 255, 238));
HslColor sepia = ColorFilter.sepia(new HslColor(163.8, 100, 87.6));

Categories

Source repository

Projects using this package