Skip to content

Commit bc503dd

Browse files
andycallyifei8
authored andcommitted
fix: fix combined with background images.
1 parent ea96031 commit bc503dd

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed
Loading

integration_tests/specs/css/css-backgrounds/background-image.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,33 @@ describe('background image', function() {
6666
await snapshot(0.1);
6767
});
6868

69+
it('should work with css vars', async () => {
70+
const style = `
71+
:root {
72+
--background-end-rgb: 255, 255, 255;
73+
--background-end-rgb-2: 0,0,0;
74+
}
75+
76+
.box {
77+
width: 100px;
78+
height: 100px;
79+
background: linear-gradient(
80+
to bottom,
81+
rgb(var(--background-end-rgb)),
82+
rgb(var(--background-end-rgb-2)));
83+
}
84+
`;
85+
const styleEle = document.createElement('style');
86+
styleEle.innerHTML = style;
87+
document.head.appendChild(styleEle);
88+
89+
const container = createElement('div', {
90+
className: 'box'
91+
});
92+
document.body.appendChild(container);
93+
await snapshot();
94+
});
95+
6996
it("computed", async () => {
7097
let target;
7198
target = createElement('div', {

webf/lib/src/css/background.dart

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ class CSSBackground {
678678
}
679679
}
680680

681-
void _applyColorAndStops(int start, List<String> args, List<Color?> colors, List<double?> stops,
681+
void _applyColorAndStops(int start, List<String> args, List<Color> colors, List<double> stops,
682682
RenderStyle renderStyle, String propertyName,
683683
[double? gradientLength]) {
684684
// colors should more than one, otherwise invalid
@@ -688,8 +688,10 @@ void _applyColorAndStops(int start, List<String> args, List<Color?> colors, List
688688
List<CSSColorStop> colorGradients =
689689
_parseColorAndStop(args[i].trim(), renderStyle, propertyName, (i - start) * grow, gradientLength);
690690
for (var colorStop in colorGradients) {
691-
colors.add(colorStop.color);
692-
stops.add(colorStop.stop);
691+
if (colorStop.color != null) {
692+
colors.add(colorStop.color!);
693+
stops.add(colorStop.stop!);
694+
}
693695
}
694696
}
695697
}
@@ -701,15 +703,8 @@ List<CSSColorStop> _parseColorAndStop(String src, RenderStyle renderStyle, Strin
701703
List<CSSColorStop> colorGradients = [];
702704
// rgba may contain space, color should handle special
703705
if (src.startsWith('rgba(') || src.startsWith('rgb(')) {
704-
int indexOfRgbaEnd = src.indexOf(')');
705-
if (indexOfRgbaEnd == -1) {
706-
// rgba parse error
707-
return colorGradients;
708-
}
706+
int indexOfRgbaEnd = src.lastIndexOf(')');
709707
strings.add(src.substring(0, indexOfRgbaEnd + 1));
710-
if (indexOfRgbaEnd + 1 < src.length) {
711-
strings.addAll(src.substring(indexOfRgbaEnd + 1).trim().split(' '));
712-
}
713708
} else {
714709
strings = src.split(' ');
715710
}

0 commit comments

Comments
 (0)