Skip to content

Commit 671ee1e

Browse files
Bump enhanced_gradients to Flutter 3.27 (#418)
* Bump enhanced_gradients to Flutter 3.27 * Fix GitHub Actions * Update tests * Update packages/enhanced_gradients/CHANGELOG.md Co-authored-by: Piotr Rogulski <[email protected]> --------- Co-authored-by: Piotr Rogulski <[email protected]>
1 parent df6b8b8 commit 671ee1e

File tree

9 files changed

+43
-27
lines changed

9 files changed

+43
-27
lines changed

.github/workflows/enhanced_gradients-publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: enhanced_gradients publish
22

33
on:
44
push:
5-
tags: ['enhanced_gradients-v*']
5+
tags: ["enhanced_gradients-v*"]
66

77
jobs:
88
publish:
@@ -25,12 +25,12 @@ jobs:
2525
- name: Set up Dart
2626
uses: dart-lang/setup-dart@v1
2727
with:
28-
sdk: 3.3
28+
sdk: 3.6
2929

3030
- name: Set up Flutter
3131
uses: subosito/flutter-action@v2
3232
with:
33-
flutter-version: 3.19.x
33+
flutter-version: 3.27.x
3434
cache: true
3535

3636
- name: Publish and release

.github/workflows/enhanced_gradients-test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ name: enhanced_gradients test
33
on:
44
push:
55
branches: [master]
6-
tags-ignore: ['enhanced_gradients-v*']
6+
tags-ignore: ["enhanced_gradients-v*"]
77
paths:
8-
- 'packages/enhanced_gradients/**'
8+
- "packages/enhanced_gradients/**"
99
pull_request:
1010
branches: [master]
1111
paths:
12-
- 'packages/enhanced_gradients/**'
12+
- "packages/enhanced_gradients/**"
1313
# Run a check daily due to the dependency on `material_color_utilities: any`
1414
schedule:
15-
- cron: '0 17 * * *'
15+
- cron: "0 17 * * *"
1616

1717
jobs:
1818
test:
@@ -23,8 +23,8 @@ jobs:
2323
fail-fast: false
2424
matrix:
2525
include:
26-
- version: '3.19.x'
27-
- channel: 'stable'
26+
- version: "3.27.x"
27+
- channel: "stable"
2828

2929
defaults:
3030
run:

packages/enhanced_gradients/.fvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"flutter": "3.19.6"
2+
"flutter": "3.27.2"
33
}

packages/enhanced_gradients/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.0.0
2+
3+
- BREAKING CHANGE: Raise minimum Flutter version to 3.27.0, which supports wide gamut color spaces.
4+
15
## 2.0.0
26

37
- BREAKING CHANGE: Raise minimum Flutter version to 3.19.0. Previous versions of enhanced_gradients were incompatible with Flutter 3.19 due to dependency constraints.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: package:flutter_lints/flutter.yaml
1+
include: package:leancode_lint/analysis_options.yaml

packages/enhanced_gradients/example/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ publish_to: "none"
44
version: 0.1.0
55

66
environment:
7-
sdk: ">=3.0.0 <4.0.0"
8-
flutter: ">=3.10.0"
7+
sdk: ">=3.6.0 <4.0.0"
8+
flutter: ">=3.27.0"
99

1010
dependencies:
1111
enhanced_gradients:
@@ -16,7 +16,7 @@ dependencies:
1616
dev_dependencies:
1717
flutter_test:
1818
sdk: flutter
19-
flutter_lints: ^2.0.0
19+
leancode_lint: ^15.0.0
2020

2121
flutter:
2222
uses-material-design: true

packages/enhanced_gradients/lib/src/hct_color_tween.dart

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,31 @@ Color? lerpHct(Color? colorA, Color? colorB, double t) =>
2727
};
2828

2929
Color _lerpHctNonNullable(Color colorA, Color colorB, double t) {
30-
final beginHct = Hct.fromInt(colorA.value);
31-
final endHct = Hct.fromInt(colorB.value);
30+
final beginHct = Hct.fromInt(_colorToInt(colorA));
31+
final endHct = Hct.fromInt(_colorToInt(colorB));
3232

33-
final opacity = lerpDouble(colorA.opacity, colorB.opacity, t)!;
33+
final alpha = lerpDouble(colorA.a, colorB.a, t)!;
3434
final hue = lerpDegrees(beginHct.hue, endHct.hue, t)!;
3535
final chroma = lerpDouble(beginHct.chroma, endHct.chroma, t)!;
3636
final tone = lerpDouble(beginHct.tone, endHct.tone, t)!;
3737

3838
return Color(
3939
Hct.from(hue, chroma, tone).toInt(),
40-
).withOpacity(opacity);
40+
).withValues(alpha: alpha);
4141
}
4242

43-
Color _scaleAlpha(Color a, double factor) {
44-
return a.withAlpha((a.alpha * factor).round().clamp(0, 255));
43+
Color _scaleAlpha(Color color, double factor) {
44+
return color.withValues(alpha: color.a * factor);
45+
}
46+
47+
/// [Hct] requires int values, so we need to convert [Color].
48+
int _colorToInt(Color color) {
49+
return _floatToInt8(color.a) << 24 |
50+
_floatToInt8(color.r) << 16 |
51+
_floatToInt8(color.g) << 8 |
52+
_floatToInt8(color.b) << 0;
53+
}
54+
55+
int _floatToInt8(double x) {
56+
return (x * 255.0).round() & 0xff;
4557
}

packages/enhanced_gradients/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: enhanced_gradients
2-
version: 2.0.0
2+
version: 3.0.0
33
homepage: https://github.com/leancodepl/flutter_corelibrary/tree/master/packages/enhanced_gradients
44
repository: https://github.com/leancodepl/flutter_corelibrary
55
description: >-
@@ -10,7 +10,7 @@ environment:
1010
flutter: ">=3.19.0"
1111

1212
dependencies:
13-
collection: ^1.17.1
13+
collection: ^1.19.0
1414
flutter:
1515
sdk: flutter
1616
material_color_utilities: any
@@ -19,5 +19,5 @@ dev_dependencies:
1919
flutter_test:
2020
sdk: flutter
2121
glados: ^1.1.6
22-
leancode_lint: ">=12.1.0 <15.0.0"
22+
leancode_lint: ^15.0.0
2323
meta: ^1.9.1

packages/enhanced_gradients/test/src/hct_color_tween_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ void main() {
2626
(colorB, t) {
2727
final result = lerpHct(null, colorB, t);
2828

29-
final resultAlpha = result!.alpha;
30-
final expectedAlpha = colorB.alpha * t;
29+
final resultAlpha = result!.a;
30+
final expectedAlpha = colorB.a * t;
3131

3232
expect(resultAlpha, closeTo(expectedAlpha, 1));
3333
});
@@ -37,8 +37,8 @@ void main() {
3737
(colorA, t) {
3838
final result = lerpHct(colorA, null, t);
3939

40-
final resultAlpha = result!.alpha;
41-
final expectedAlpha = colorA.alpha * (1 - t);
40+
final resultAlpha = result!.a;
41+
final expectedAlpha = colorA.a * (1 - t);
4242

4343
expect(resultAlpha, closeTo(expectedAlpha, 1));
4444
});

0 commit comments

Comments
 (0)