TinyColor is a small library for Flutter color manipulation and conversion
A port of tinycolor2 by Brian Grinstead
A tinycolor receives a Color
as parameter.
import 'package:tinycolor/tinycolor.dart';
final TinyColor = TinyColor(Colors.green);
The package uses Pigment by Bregy Malpartida Ramos to convert strings to Color
TinyColor.fromString('#FE5567';
TinyColor.fromRGB(r: 255, g: 255, b:255);
HslColor color = HslColor(h: 250, s: 57, l: 30);
TinyColor.fromHSL(color);
HSVColor color = HSVColor(h: 250, s: 57, v: 30);
TinyColor.fromHSV(color);
Returns de flutter Color
after operations
final Color color = TinyColor(Colors.white).color;
Returns the perceived brightness of a color, from 0-255
, as defined by Web Content Accessibility Guidelines (Version 1.0).
TinyColor.fromString("#ffffff").getBrightness(); // 255
TinyColor.fromString("#000000").getBrightness(); // 0
Return a boolean indicating whether the color's perceived brightness is light.
TinyColor.fromString("#ffffff").isLight(); // true
TinyColor.fromString("#000000").isLight(); // false
Return a boolean indicating whether the color's perceived brightness is dark.
TinyColor.fromString("#ffffff").isDark(); // false
TinyColor.fromString("#000000").isDark(); // true
Return the perceived luminance of a color, a shorthand for flutter Color.computeLuminance
TinyColor.fromString("#ffffff").getLuminance();
Sets the alpha value on the current color.
final color = TinyColor(Colors.red).setAlpha(10);
Sets the opacity value on the current color.
final color = TinyColor(Colors.red).setOpacity(0.5);
These methods manipulate the current color, and return it for chaining. For instance:
TinyColor(Colors.red).lighten().desaturate().color;
lighten: function(amount = 10) -> TinyColor
. Lighten the color a given amount, from 0 to 100. Providing 100 will always return white.
TinyColor(Colors.red).lighten().color;
TinyColor(Colors.red).lighten(100).color;
brighten: function(amount = 10) -> TinyColor
. Brighten the color a given amount, from 0 to 100.
TinyColor(Colors.white).brighten().color;'
darken: function(amount = 10) -> TinyColor
. Darken the color a given amount, from 0 to 100. Providing 100 will always return black.
TinyColor(Colors.red).darken().color;
TinyColor(Colors.red).darken(100).color;
Mix the color with pure white, from 0 to 100. Providing 0 will do nothing, providing 100 will always return white.
TinyColor(Color.red).tint().color;
TinyColor(Color.red).tint(100).color;
Mix the color with pure black, from 0 to 100. Providing 0 will do nothing, providing 100 will always return black.
TinyColor(Colors.red).shade().color;
TinyColor(Colors.red).shade(100).color;
desaturate: function(amount = 10) -> TinyColor
. Desaturate the color a given amount, from 0 to 100. Providing 100 will is the same as calling greyscale
.
TinyColor(Colors.red).desaturate().color;
TinyColor(Colors.red).desaturate(100).color;
saturate: function(amount = 10) -> TinyColor
. Saturate the color a given amount, from 0 to 100.
TinyColor(Colors.red).saturate().color;
greyscale: function() -> TinyColor
. Completely desaturates a color into greyscale. Same as calling desaturate(100)
.
TinyColor(Colors.red).greyscale().color;"
spin: function(amount = 0) -> TinyColor
. Spin the hue a given amount, from -360 to 360. Calling with 0, 360, or -360 will do nothing (since it sets the hue back to what it was before).
TinyColor(Colors.red).spin(180).color;
// spin(0) and spin(360) do nothing
TinyColor(Colors.red).spin(0).color;
TinyColor(Colors.red).spin(360).color;
clone: function() -> TinyColor
.
Instantiate a new TinyColor object with the same color. Any changes to the new one won't affect the old one.
final color1 = new TinyColor(Colors.red);
final color2 = color1.clone();
color2.setAlpha(20);
*Fixed compatibility issues with dart 2.1 and pigment 1.0.3
Add this to your package's pubspec.yaml file:
dependencies:
tinycolor: ^1.0.2
You can install packages from the command line:
with Flutter:
$ flutter packages get
Alternatively, your editor might support flutter packages get
.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:tinycolor/tinycolor.dart';
Version | Uploaded | Documentation | Archive |
---|---|---|---|
1.0.2 | Aug 17, 2018 |
|
|
1.0.1 | Aug 4, 2018 |
|
|
1.0.0 | Aug 4, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
81
|
Health:
Code health derived from static analysis.
[more]
|
99
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
90
|
Overall:
Weighted score of the above.
[more]
|
88
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter
References Flutter, and has no conflicting libraries.
Document public APIs. (-1 points)
51 out of 51 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.
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 tinycolor.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.0.0-dev.48.0 <3.0.0 | ||
flutter | 0.0.0 | ||
pigment | ^1.0.3 | 1.0.3 | |
Transitive dependencies | |||
collection | 1.14.11 | ||
meta | 1.1.6 | 1.1.7 | |
sky_engine | 0.0.99 | ||
typed_data | 1.1.6 | ||
vector_math | 2.0.8 | ||
Dev dependencies | |||
flutter_test |