Skip to content

Commit 27ec9ab

Browse files
authored
Preserve transform when using *Gradient:withOpacity (flutter#154908)
i don't think it was intentional to lose it? - [] All existing and new tests are passing.
1 parent d95821c commit 27ec9ab

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

packages/flutter/lib/src/painting/gradient.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ class LinearGradient extends Gradient {
570570
],
571571
stops: stops,
572572
tileMode: tileMode,
573+
transform: transform,
573574
);
574575
}
575576
}
@@ -872,6 +873,7 @@ class RadialGradient extends Gradient {
872873
tileMode: tileMode,
873874
focal: focal,
874875
focalRadius: focalRadius,
876+
transform: transform,
875877
);
876878
}
877879
}
@@ -1149,6 +1151,7 @@ class SweepGradient extends Gradient {
11491151
],
11501152
stops: stops,
11511153
tileMode: tileMode,
1154+
transform: transform,
11521155
);
11531156
}
11541157
}

packages/flutter/test/painting/gradient_test.dart

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,32 @@ void main() {
445445
Color(0x80777777),
446446
Color(0x80444444),
447447
],
448-
),);
448+
));
449+
});
450+
451+
test('LinearGradient withOpacity() preserves transform', () {
452+
const LinearGradient testGradient = LinearGradient(
453+
begin: Alignment.bottomRight,
454+
end: Alignment.topCenter,
455+
colors: <Color>[
456+
Color(0xFFFFFFFF),
457+
Color(0xAF777777),
458+
Color(0x44444444),
459+
],
460+
transform: GradientRotation(1),
461+
);
462+
final LinearGradient actual = testGradient.withOpacity(0.5);
463+
464+
expect(actual, const LinearGradient(
465+
begin: Alignment.bottomRight,
466+
end: Alignment.topCenter,
467+
colors: <Color>[
468+
Color(0x80FFFFFF),
469+
Color(0x80777777),
470+
Color(0x80444444),
471+
],
472+
transform: GradientRotation(1),
473+
));
449474
});
450475

451476
test('RadialGradient with AlignmentDirectional', () {
@@ -765,6 +790,36 @@ void main() {
765790
],
766791
));
767792
});
793+
794+
test('RadialGradient withOpacity() preserves transform', () {
795+
const RadialGradient testGradient = RadialGradient(
796+
center: Alignment.topLeft,
797+
focal: Alignment.centerLeft,
798+
radius: 20.0,
799+
focalRadius: 10.0,
800+
colors: <Color>[
801+
Color(0xFFFFFFFF),
802+
Color(0xAF777777),
803+
Color(0x44444444),
804+
],
805+
transform: GradientRotation(1),
806+
);
807+
final RadialGradient actual = testGradient.withOpacity(0.5);
808+
809+
expect(actual, const RadialGradient(
810+
center: Alignment.topLeft,
811+
focal: Alignment.centerLeft,
812+
radius: 20.0,
813+
focalRadius: 10.0,
814+
colors: <Color>[
815+
Color(0x80FFFFFF),
816+
Color(0x80777777),
817+
Color(0x80444444),
818+
],
819+
transform: GradientRotation(1),
820+
));
821+
});
822+
768823
test('SweepGradient lerp test', () {
769824
const SweepGradient testGradient1 = SweepGradient(
770825
center: Alignment.topLeft,
@@ -997,6 +1052,32 @@ void main() {
9971052
],
9981053
));
9991054
});
1055+
1056+
test('SweepGradient withOpacity() preserves transform', () {
1057+
const SweepGradient testGradient = SweepGradient(
1058+
center: Alignment.topLeft,
1059+
endAngle: math.pi / 2,
1060+
colors: <Color>[
1061+
Color(0xFFFFFFFF),
1062+
Color(0xAF777777),
1063+
Color(0x44444444),
1064+
],
1065+
transform: GradientRotation(1),
1066+
);
1067+
final SweepGradient actual = testGradient.withOpacity(0.5);
1068+
1069+
expect(actual, const SweepGradient(
1070+
center: Alignment.topLeft,
1071+
endAngle: math.pi / 2,
1072+
colors: <Color>[
1073+
Color(0x80FFFFFF),
1074+
Color(0x80777777),
1075+
Color(0x80444444),
1076+
],
1077+
transform: GradientRotation(1),
1078+
));
1079+
});
1080+
10001081
test('Gradient lerp test (with RadialGradient)', () {
10011082
const RadialGradient testGradient1 = RadialGradient(
10021083
center: Alignment.topLeft,

0 commit comments

Comments
 (0)