diff --git a/lib/src/conversion.dart b/lib/src/conversion.dart index 12f8a81..760ab0d 100644 --- a/lib/src/conversion.dart +++ b/lib/src/conversion.dart @@ -2,13 +2,11 @@ import 'dart:math' as Math; import 'dart:ui'; import 'package:flutter/painting.dart'; -import 'package:meta/meta.dart'; import 'hsl_color.dart'; import 'util.dart'; -HslColor rgbToHsl( - {@required double r, @required double g, @required double b}) { +HslColor rgbToHsl({required double r, required double g, required double b}) { r = bound01(r, 255.0); g = bound01(g, 255.0); b = bound01(b, 255.0); @@ -67,7 +65,7 @@ HSVColor colorToHsv(Color color) { } HSVColor rgbToHsv( - {@required int r, @required int g, @required int b, @required int a}) { + {required int r, required int g, required int b, required int a}) { return colorToHsv(Color.fromARGB(a, r, g, b)); } diff --git a/lib/src/hsl_color.dart b/lib/src/hsl_color.dart index 2a83f5d..0abf1d5 100644 --- a/lib/src/hsl_color.dart +++ b/lib/src/hsl_color.dart @@ -4,7 +4,7 @@ class HslColor { double l; double a; - HslColor({this.h, this.s, this.l, this.a = 0.0}); + HslColor({required this.h, required this.s, required this.l, this.a = 0.0}); String toString() { return "HSL(h: $h, s: $s, l: $l, a: $a)"; diff --git a/lib/src/tinycolor.dart b/lib/src/tinycolor.dart index 7daf1ff..3d842c9 100644 --- a/lib/src/tinycolor.dart +++ b/lib/src/tinycolor.dart @@ -2,7 +2,6 @@ import 'dart:math' as Math; import 'dart:ui'; import 'package:flutter/painting.dart'; -import 'package:meta/meta.dart'; import 'package:pigment/pigment.dart'; import 'conversion.dart'; @@ -13,18 +12,15 @@ export 'hsl_color.dart'; export 'color_extension.dart'; class TinyColor { - Color originalColor; + final Color originalColor; Color _color; - TinyColor(Color color) { - this.originalColor = - Color.fromARGB(color.alpha, color.red, color.green, color.blue); - this._color = - Color.fromARGB(color.alpha, color.red, color.green, color.blue); - } + TinyColor(Color color) + : this.originalColor = color, + _color = color.clone(); factory TinyColor.fromRGB( - {@required int r, @required int g, @required int b, int a = 100}) { + {required int r, required int g, required int b, int a = 100}) { return TinyColor(Color.fromARGB(a, r, g, b)); } @@ -144,7 +140,7 @@ class TinyColor { return TinyColor.fromHSL(hsl); } - TinyColor mix({@required Color input, int amount = 50}) { + TinyColor mix({required Color input, int amount = 50}) { final p = amount / 100.0; final color = Color.fromARGB( ((input.alpha - _color.alpha) * p + _color.alpha).round(), @@ -166,10 +162,10 @@ class TinyColor { @override bool operator ==(Object other) => - identical(this, other) || - other is TinyColor && - runtimeType == other.runtimeType && - color == other.color; + identical(this, other) || + other is TinyColor && + runtimeType == other.runtimeType && + color == other.color; @override int get hashCode => color.hashCode; @@ -177,3 +173,9 @@ class TinyColor { @Deprecated('Use == instead.') bool equals(Object other) => this == other; } + +extension _ on Color { + Color clone() { + return Color.fromARGB(alpha, red, green, blue); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 3493701..9584564 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,14 +4,13 @@ version: 2.0.0 homepage: https://github.com/TinyCommunity/tinycolor2 environment: - sdk: ">=2.6.0 <3.0.0" + sdk: ">=2.12.0-0 <3.0.0" flutter: ">=1.12.0 <3.0.0" dependencies: - pigment: ^1.0.3 - meta: ^1.2.2 flutter: sdk: flutter + pigment: ^1.0.4 dev_dependencies: flutter_test: