Skip to content

Gradient strokes: honour Paint.shader when style is PaintingStyle.stroke #113

Backlog

Description

@tayormi

Select your plan

Standard - priority support

Confirmations

  • I searched the existing feature requests and this is not a duplicate.

Framework or plugin?

Framework

Platform

Both

Use case

A shader on a stroked Paint is dropped. The canvas docs say so: "When style = PaintingStyle.stroke, the shader is silently ignored and the paint's solid color is used instead — gradient strokes are not supported" (lib/src/widgets/custom_paint.dart). So the most common gradient drawing, a progress or countdown ring, can't be drawn as one arc:

canvas.drawArc(rect, -pi / 2, sweep, false, Paint()
  ..style = PaintingStyle.stroke
  ..strokeWidth = 8
  ..strokeCap = StrokeCap.round
  ..shader = ui.Gradient.linear(rect.topLeft, rect.bottomRight, [a, b]));
// draws a solid arc in paint.color

Our workaround draws the arc as 48 short solid segments per circle, each in an interpolated colour, which shows banding on large rings and costs many draw calls. Filling a hand-built ring path works for a full ring but not for an arc with round caps.

Proposal

For a stroke with a shader, stroke the path to an outline and fill that outline with the gradient: on iOS, CGPath.copy(strokingWithWidth:lineCap:lineJoin:miterLimit:) as the mask of a gradient layer (or CGContext.replacePathWithStrokedPath() then clip and draw the gradient); on Android, Paint.setShader already applies to strokes.

If that's not planned soon, a one-time debug log when a shader is dropped would save people from finding out on device.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions