Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/color_extension.dart → lib/src/color_extension.dart
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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;
}
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/tinycolor.dart → lib/src/tinycolor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions lib/tinycolor2.dart
Original file line number Diff line number Diff line change
@@ -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';
27 changes: 27 additions & 0 deletions test/tinycolor_test.dart
Original file line number Diff line number Diff line change
@@ -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));
},
);
}
3 changes: 1 addition & 2 deletions test/util_test.dart
Original file line number Diff line number Diff line change
@@ -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", () {
Expand Down