Skip to content

SweepGradient (conic gradient) for decorations and shaders #112

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

There is no sweep (conic) gradient. painting.dart has LinearGradient and RadialGradient, and the canvas Gradient has two kinds ("1 = linear, 2 = radial", lib/src/widgets/custom_paint.dart), so BoxDecoration(gradient: SweepGradient(...)) doesn't compile and a CustomPaint can't fill with one.

We wanted a rotating gradient edge around a card and a progress ring with a sweep of colour. Both platforms have this natively (CAGradientLayer.type = .conic on iOS, android.graphics.SweepGradient). Our workaround is our own small Swift plugin just for this one effect, iOS only. An SkSL shader through dartnative_skia would also work but adds several MB to the app for one gradient.

Proposal

Add Flutter's SweepGradient to painting.dart, usable in BoxDecoration and through createShader for Paint.shader, and a Gradient.sweep factory in package:dartnative/canvas.dart:

Container(
  decoration: const BoxDecoration(
    shape: BoxShape.circle,
    gradient: SweepGradient(
      center: Alignment.center,
      startAngle: 0,
      endAngle: 2 * pi,
      colors: [Color(0xFF36E7A6), Color(0xFF8B7CFF), Color(0xFF36E7A6)],
    ),
  ),
);

canvas.drawCircle(c, r, Paint()
  ..shader = ui.Gradient.sweep(c, [a, b, a]));

Mapped to CAGradientLayer with type = .conic on iOS and SweepGradient on Android.

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