diff --git a/lib/color_extension.dart b/lib/src/color_extension.dart similarity index 92% rename from lib/color_extension.dart rename to lib/src/color_extension.dart index af86a7b..235d4b2 100644 --- a/lib/color_extension.dart +++ b/lib/src/color_extension.dart @@ -1,13 +1,13 @@ import 'package:flutter/painting.dart'; import 'tinycolor.dart'; -/// Extends the Color class to allow direct TinyColor manipulation nativly +/// Extends the Color class to allow direct TinyColor manipulation natively extension TinyColorExtension on Color { /// Converts standard Color to TinyColor object TinyColor toTinyColor() => TinyColor(this); HSVColor toHsv() => TinyColor(this).toHsv(); - + HslColor toHsl() => TinyColor(this).toHsl(); /// Lighten the color a given amount, from 0 to 100. Providing 100 will always return white. @@ -26,7 +26,8 @@ extension TinyColorExtension on Color { Color shade([int amount = 10]) => TinyColor(this).shade(amount).color; /// Desaturate the color a given amount, from 0 to 100. Providing 100 will is the same as calling greyscale. - Color desaturate([int amount = 10]) => TinyColor(this).desaturate(amount).color; + Color desaturate([int amount = 10]) => + TinyColor(this).desaturate(amount).color; /// Saturate the color a given amount, from 0 to 100. Color saturate([int amount = 10]) => TinyColor(this).saturate(amount).color; @@ -53,5 +54,6 @@ extension TinyColorExtension on Color { Color get compliment => TinyColor(this).complement().color; /// Blends the color with another color a given amount, from 0 - 100, default 50. - Color mix(Color toColor, [int amount = 50]) => TinyColor(this).mix(input: toColor, amount: amount).color; + Color mix(Color toColor, [int amount = 50]) => + TinyColor(this).mix(input: toColor, amount: amount).color; } diff --git a/lib/conversion.dart b/lib/src/conversion.dart similarity index 100% rename from lib/conversion.dart rename to lib/src/conversion.dart diff --git a/lib/hsl_color.dart b/lib/src/hsl_color.dart similarity index 100% rename from lib/hsl_color.dart rename to lib/src/hsl_color.dart diff --git a/lib/tinycolor.dart b/lib/src/tinycolor.dart similarity index 97% rename from lib/tinycolor.dart rename to lib/src/tinycolor.dart index 28cac85..0b9ae3c 100644 --- a/lib/tinycolor.dart +++ b/lib/src/tinycolor.dart @@ -57,12 +57,12 @@ class TinyColor { } TinyColor setAlpha(int alpha) { - _color.withAlpha(alpha); + _color = _color.withAlpha(alpha); return this; } TinyColor setOpacity(double opacity) { - _color.withOpacity(opacity); + _color = _color.withOpacity(opacity); return this; } diff --git a/lib/util.dart b/lib/src/util.dart similarity index 100% rename from lib/util.dart rename to lib/src/util.dart diff --git a/lib/tinycolor2.dart b/lib/tinycolor2.dart new file mode 100644 index 0000000..9104354 --- /dev/null +++ b/lib/tinycolor2.dart @@ -0,0 +1,7 @@ +library tinycolor2; + +export 'src/color_extension.dart'; +export 'src/conversion.dart'; +export 'src/hsl_color.dart'; +export 'src/tinycolor.dart'; +export 'src/util.dart'; diff --git a/test/tinycolor_test.dart b/test/tinycolor_test.dart new file mode 100644 index 0000000..093cebe --- /dev/null +++ b/test/tinycolor_test.dart @@ -0,0 +1,27 @@ +import 'dart:ui'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:tinycolor2/tinycolor2.dart'; + +void main() { + test( + "setAlpha updates alpha value of color", + () { + TinyColor color = TinyColor(Color(0xFFFFFFFF)); + color.setAlpha(0x00); + expect(color.color.alpha, 0x00); + }, + ); + + test( + "setOpacity updates opacity value of color", + () { + TinyColor color = TinyColor(Color(0xFFFFFFFF).withOpacity(1.0)); + color.setOpacity(0.5); + + // underlying dart implementation converts the opacity value to an + // int, then back into a double. Thus some precision is loss. + expect(color.color.opacity, moreOrLessEquals(0.5, epsilon: 1e-2)); + }, + ); +} diff --git a/test/util_test.dart b/test/util_test.dart index eb7120a..e050c33 100644 --- a/test/util_test.dart +++ b/test/util_test.dart @@ -1,6 +1,5 @@ import 'package:flutter_test/flutter_test.dart'; -//import 'package:test/test.dart'; -import 'package:tinycolor/util.dart'; +import 'package:tinycolor2/tinycolor2.dart'; void main() { test("bound01 values", () {