MichaelFenwick / Color

A simple Dart package exposing a Color class which can be used to create, convert, and compare colors.
http://pub.dartlang.org/packages/color
MIT License
52 stars 18 forks source link

Updating for use with Flutter #18

Open Skquark opened 6 years ago

Skquark commented 6 years ago

This is a great utility package with some useful missing features, but would be nice if it were refactored for use with Flutter natively.. It's still functional being Dart, but doesn't work too well with the built-in Color type. For one, the class name conflicts with the existing Color class, it uses num instead of double or int, and a few other bits that make it dated from 3 years ago. I suggest reworking it a bit and re-releasing with a different name so us Flutterers can get some life out of it. I mostly needed it for darken and lighten, so I adapted a function so I can put it to use, even though it's a bit clumsy. Here's my adapter in case it's useful to someone:

import 'package:color/color.dart' as colorUtil;

Color colorDarken(Color color, double amount) {
  colorUtil.RgbColor rgbNew = colorUtil.ColorFilter.darken(
    colorUtil.RgbColor(color.red, color.green, color.blue).toCielabColor(), [amount]).toRgbColor();
  return Color.fromARGB(255, rgbNew.r.toInt(), rgbNew.g.toInt(), rgbNew.b.toInt());
}
Color colorLighten(Color color, double amount) {
  colorUtil.RgbColor rgbNew = colorUtil.ColorFilter.lighten(
    colorUtil.RgbColor(color.red, color.green, color.blue).toCielabColor(), [amount]).toRgbColor();
  return Color.fromARGB(255, rgbNew.r.toInt(), rgbNew.g.toInt(), rgbNew.b.toInt());
}
SergeShkurko commented 5 years ago

You can usage another package maked specialy for flutter

(Inspired by it package)