A Dart plugin for defining color constants and converting them between color spaces.
For use with Flutter, see: http://github.com/james-alex/flutter_color_models
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].
Converting Colors Between Spaces #
Each color model has methods to convert itself to every other color model.
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
[0.1.2] - July 31, 2019
- All ColorModels now @override hashCode.
[0.1.1] - July 25, 2019
Added a private constructor to the ColorConverter class.
Minor formatting changes.
[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:
dependencies: color_models: ^0.1.2
2. Install it
You can install packages from the command line:
$ pub get
$ flutter pub get
Alternatively, your editor might support
pub get or
flutter pub get.
Check the docs for your editor to learn more.
3. Import it
Now in your Dart code, you can use:
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]
We analyzed this package on Dec 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.7.0
- pana: 0.13.1+4
Maintain an example. (-10 points)
Create a short demo in the
example/ directory to show how to use this package.
Common filename patterns include
color_models.dart. Packages with multiple examples should provide
For more information see the pub package layout conventions.
|Dart SDK||>=2.1.0 <3.0.0|