beginGradientFill method

Graphics beginGradientFill(
  1. GradientType type,
  2. List<Color> colors, {
  3. List<double>? ratios,
  4. Alignment? begin,
  5. Alignment? end,
  6. double rotation = 0,
  7. TileMode tileMode = TileMode.clamp,
  8. Rect? gradientBox,
  9. double radius = 0.5,
  10. double focalRadius = 0.0,
  11. double sweepStartAngle = 0.0,
  12. double sweepEndAngle = 6.2832,
})

Begins filling a shape with the specified gradient.

If _holeMode is true, the method will do nothing and return this Graphics object.

If ratios is not specified, the method creates an equal distribution of color across the gradient.

If begin is not specified, the method uses Alignment.center.

If end is not specified, the method uses Alignment.centerRight.

If rotation is not specified, the method uses 0.0.

If tileMode is not specified, the method uses TileMode.clamp.

If gradientBox is specified, the method uses it to create a gradient shader that matches the bounding box of the object.

If radius is not specified, the method uses 0.5.

If focalRadius is not specified, the method uses 0.0.

If sweepStartAngle is not specified, the method uses 0.0.

If sweepEndAngle is not specified, the method uses 6.2832.

Returns this Graphics object after beginning the gradient fill. For GradientType.radial, end is used for RadialGradient.focal, check the RadialGradient docs to understand the relation with focalRadius

Implementation

Graphics beginGradientFill(
  GradientType type,
  List<Color> colors, {
  List<double>? ratios,
  Alignment? begin,
  Alignment? end,
  double rotation = 0,
  TileMode tileMode = TileMode.clamp,
  Rect? gradientBox,

  /// only radial
  double radius = 0.5,
  double focalRadius = 0.0,

  /// only sweep
  double sweepStartAngle = 0.0,
  double sweepEndAngle = 6.2832,
}) {
  final gradient = _createGradient(
    type,
    colors,
    ratios,
    begin,
    end,
    rotation,
    radius,
    focalRadius,
    sweepStartAngle,
    sweepEndAngle,
    tileMode,
  );
  final paint = Paint();
  paint.style = PaintingStyle.fill;
  paint.isAntiAlias = true;
  _addFill(paint);
  if (gradientBox != null) {
    _currentDrawing!.fill!.shader = gradient.createShader(gradientBox);
  } else {
    _currentDrawing!.gradient = gradient;
  }
  return this;
}