A color library which can be used to create, convert, alter, and compare colors to be used in both Flutter and the web.
Installation 💻 #
- Add this to your package's
dependencies: color: any
- Get the package using your IDE's GUI or via command line with
$ pub get
- Import the
color_wand.dartfile in your app
Usage 🥒 #
Color objects can be constructed by either using the factory constructors of the
Color interface or by directly
RgbColor or an
HslColor using one of their constructors.
- From HEX:
- From a HEX string:
- From RGB:
Color.rgb(red: red, green: green, blue: blue)
- From RGBA:
Color.rgba(red: red, green: green, blue: blue, alpha: alpha)
- From RGBO:
Color.rgbo(red: red, green: green, blue: blue, opacity: opacity)
- From HSL:
Color.hsl(hue: hue, saturation: saturation, lightness: lightness)
- From HSLO:
Color.hslo(hue: hue, saturation: saturation, lightnesss: lightness, opacity: opacity)
- From the lower 32 bits of an integer to be used e.g. for fast conversion to and from the Flutter color lib:
Colors are immutable, and most of them can be created using const constructors:
Color color = const Color.hex(0x12345678);
Colors can be converted from one color space to another by calling
toHsl on them.
Colors can be compared using the
== operator, which will implicitly convert the color to an
RgbColor and then compare there values.
Colors can be converted to a CSS color string by using one of the different implementations of the
Available formats are:
rgb(red, green, blue)or
rgb(red, green, blue, alpha)
rgba(red, green, blue)or
rgba(red, green, blue, alpha)
hsl(hue, saturation, lightness)or
hsl(hue, saturation, lightness, alpha)
hsla(hue, saturation, lightness)or
hsla(hue, saturation, lightness, alpha)
Most of the formats can be customized to e.g. represent the values as percentages or decimal numbers.
final rgbFormat = RgbFormat(rgbStyle: PercentOrAlpha.alpha); final hslFormat = HslFormat(hueStyle: DegreeOrDecimal.degree); final color = Color.hsl(24, 100, 50); assert(rgbFormat.format(color) == 'rgb(255, 102, 0)'); assert(hslFormat.format(color) == 'hsl(24deg, 100%, 50%)');
0.0.1 ----- * Initial version 0.0.2 ----- * Drop version of meta to 1.0.0 because of compatibility issues with other packages 0.0.3 ----- * Reformat with dartfmt 0.0.4 ----- * Fix issue where HexFormat would cut of the red part of the hex string when red was 0
Use this package as a library
1. Depend on it
Add this to your package's pubspec.yaml file:
dependencies: color_wand: ^0.0.4
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 Sep 19, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
- Dart: 2.5.0
- pana: 0.12.21
Detected platforms: Flutter, web, other
No platform restriction found in primary library
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_wand.dart. Packages with multiple examples should provide
For more information see the pub package layout conventions.
Package is pre-v0.1 release. (-10 points)
While nothing is inherently wrong with versions of
0.0.*, it might mean that the author is still experimenting with the general direction of the API.