A native Dart port of @kurkle/color 0.3.2 for Flutter.

Overview

Fast and small CSS color parsing and manipulation library.

Usage

The methods of the upstream Color class are the extension KurkleColor on the Flutter Color. Each method returns a new color.

import 'dart:ui';

import 'package:flutter_kurkle_color_port/flutter_kurkle_color_port.dart';

void main() {
  const blue = Color(0xFF3366CC);
  print(blue.lighten(0.2).rotate(30).withAlphaRatio(0.5).rgbString()); // rgba(112, 92, 214, 0.5)
  print(const Color(0xFFFF0000).mix(const Color(0xFF0000FF), 0.25).hexString()); // #4000BF
  print(hexString(nameParse('steelblue'))); // #4682B4
}

The parse functions hexParse, nameParse, rgbParse and hueParse read the CSS text forms below into an RGBA. KurkleColor.fromRgbaBytes makes a Flutter Color of it.

Parsing

Supported formats:

  • named
blue
transparent
  • hex
#aaa
#bbba
#1A2b3c
#f1f2f388
  • rgb(a)
rgb(255, 255, 255)
rgb(255, 0, 0, 0.5)
rgb(50%, 50%, 50%, 50%)
rgb(0 0 100% / 80%)
rgba(200, 20, 233, 0.2)
rgba(200, 20, 233, 2e-1)
  • hsl(a)
hsl(240deg, 100%, 50.5%)
hsl(0deg 100% 50%)
hsla(12, 10%, 50%, .3)
hsla(-1.2, 10.2%, 50.9%, 0.4)
  • hwb
hwb(240, 100%, 50.5%)
hwb(244, 100%, 100%, 0.6)
  • hsv
hsv(240, 100%, 50.5%)
hsv(244, 100%, 100%, 0.6)

Libraries

flutter_kurkle_color_port
A native Dart port of @kurkle/color 0.3.2: color parsing and manipulation.