Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to null safety #24

Merged
merged 6 commits into from
Jul 13, 2021
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
6 changes: 2 additions & 4 deletions lib/src/conversion.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/hsl_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand Down
30 changes: 16 additions & 14 deletions lib/src/tinycolor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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));
}

Expand Down Expand Up @@ -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(),
Expand All @@ -166,14 +162,20 @@ 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;

@Deprecated('Use == instead.')
bool equals(Object other) => this == other;
}

extension _ on Color {
Color clone() {
return Color.fromARGB(alpha, red, green, blue);
}
}
5 changes: 2 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down