Introduction
Color Utils is an useful package for play with colors.
Features
- Mix multiple colors
- Match percentage of two colors
- Generate color from hex string
- Color cooker
get a colour palette list using the base colours list for the target colour
Getting started
- Install dependencies
color_utils:
git:
url: https://github.com/shawon1fb/color_utils.git
- Import dependencies
import 'package:color_utils/flutter_color_utils.dart';
Usage
Useful examples for color_utils users. more examples
to /test
folder.
1. Multi colors mixer
Color red = const Color(0xFF890041);
Color yellow = const Color(0xffFFCE51);
Color blue = const Color(0xff00224C);
List<Color> spicyMixerList = [yellow, red, blue];
Color mix = ColorUtils.mixColors(spicyMixerList);
Color spicyMixColor = const Color(0xff83504A);
print(spicyMixColor == mix );/// true
2. HexColor String to Color
Color red = const Color(0xFF890041);
Color redHexColor = HexColor('#890041');
print(red == redHexColor);///true
print(redHexColor == red);///true
3. Match percentage of two colors
Color spicyMixColor = const Color(0xff83504A);
Color pelorousColor = const Color(0xff44AABB);
double match = spicyMixColor.match(pelorousColor);
double expected = 64.31;
print(((match - expected) <0.02));///true
4. Color cooker
Color spicyMixColor = const Color(0xff83504A);
List<Color> baseColorList = [
const Color(0xFF890041),
const Color(0xffFFCE51),
const Color(0xff00224C),
const Color(0xffFFFFFF),
const Color(0xff21211A),
];
ColorRecipe colorReversed =
ColorRecipe(baseColorsList: baseColorList, targetColor: spicyMixColor);
colorReversed.getColorRecipe(<Color>[]);
print(colorReversed.bestList);
print(colorReversed.globalMaxMatch==100.0); /// true