flutter_color_models 0.1.0+1

  • Readme
  • Changelog
  • Installing
  • 54

flutter_color_models #

A wrapper for the color_models plugin with added support for Flutter's [Color] class.

See: http://github.com/james-alex/color_models

Usage #

import 'package:flutter_color_models/flutter_color_models.dart';

Color Spaces #

color_models exposes models for the CMYK, HSI, HSL, HSP, HSV, LAB, RGB, and XYZ color spaces; represented as [CmykColor], [HsiColor], [HslColor], [HspColor], [HsvColor], [LabColor], [RgbColor], and [XyzColor] respectively.

Each model is constant and extends [ColorModel].

Casting Color to and from the ColorModels #

Each color model has method toColor() a static method fromColor() that will recast a [Color] to a [ColorModel] and vice versa, converting the color to desired color space if not called on [RgbColor].

Color color = Color(0xFFFFFF00); // yellow

CmykColor cmykColor = CmykColor.fromColor(color);
color = cmykColor.toColor();

HsiColor hsiColor = HsiColor.fromColor(color);
color = hsiColor.toColor();

HslColor hslColor = HslColor.fromColor(color);
color = hslColor.toColor();

HspColor hspColor = HspColor.fromColor(color);
color = hspColor.toColor();

HsvColor hsvColor = HsvColor.fromColor(color);
color = hsvColor.toColor();

LabColor labColor = LabColor.fromColor(color);
color = labColor.toColor();

RgbColor rgbColor = RgbColor.fromColor(color);
color = rgbColor.toColor();

XyzColor xyzColor = XyzColor.fromColor(color);
color = xyzColor.toColor();

Converting Colors Between Spaces #

Each color model has methods to convert itself to each of the other color models.

CmykColor toCmykColor();

HsiColor toHsiColor();

HslColor toHslColor();

HspColor toHspColor();

HsvColor toHsvColor();

LabColor toLabColor();

RgbColor toRgbColor();

XyzColor toXyzColor();

Altenatively, each color model has a static method from that can accept a color from any color space and returns its own type (T).

static T from(ColorModel color);
// Create a HSV color
HsvColor originalColor = HsvColor(0.3, 0.8, 0.7);

// Convert it to RGB => RgbColor(64, 179, 36)
RgbColor rgbColor = RgbColor.from(originalColor);

// Then to CMYK => CmykColor(64.25, 0, 79.89, 29.8)
CmykColor cmykColor = CmykColor.from(rgbColor);

// Back to HSV => HsvColor(0.3, 0.8, 0.7)
HsvColor hsvColor = HsvColor.from(cmykColor);

Note: All color conversions use the RGB color space as an intermediary. To minimize the loss of precision when converting between other color spaces, [RgbColor] privately stores the RGB values as [num]s rather than [int]s. The [num] values can be returned as a list with [RgbColor]'s toPreciseList() method.

[0.1.0] - July 23, 2019

  • Initial release

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  flutter_color_models: ^0.1.0+1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:flutter_color_models/flutter_color_models.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Dec 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and flutter_color_models.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
color_models ^0.1.0 0.1.2
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies