Skip to content

Commit c2e8289

Browse files
authored
Add GradientRadial paintStyle implementation (flutter#12081)
1 parent c3eea0a commit c2e8289

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

lib/web_ui/lib/src/engine/shader.dart

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class GradientLinear extends EngineGradient {
162162
}
163163
}
164164

165+
// TODO(flutter_web): Add screenshot tests when infra is ready.
165166
class GradientRadial extends EngineGradient {
166167
GradientRadial(this.center, this.radius, this.colors, this.colorStops,
167168
this.tileMode, this.matrix4)
@@ -176,7 +177,22 @@ class GradientRadial extends EngineGradient {
176177

177178
@override
178179
Object createPaintStyle(html.CanvasRenderingContext2D ctx) {
179-
throw UnimplementedError();
180+
// TODO(flutter_web): see https://github.com/flutter/flutter/issues/32819
181+
if (matrix4 != null && !Matrix4.fromFloat64List(matrix4).isIdentity()) {
182+
throw UnimplementedError('matrix4 not supported in GradientRadial shader');
183+
}
184+
final html.CanvasGradient gradient =
185+
ctx.createRadialGradient(center.dx, center.dy, 0, center.dx, center.dy, radius);
186+
if (colorStops == null) {
187+
assert(colors.length == 2);
188+
gradient.addColorStop(0, colors[0].toCssString());
189+
gradient.addColorStop(1, colors[1].toCssString());
190+
return gradient;
191+
}
192+
for (int i = 0; i < colors.length; i++) {
193+
gradient.addColorStop(colorStops[i], colors[i].toCssString());
194+
}
195+
return gradient;
180196
}
181197

182198
@override

0 commit comments

Comments
 (0)