Graphics class

A class representing graphics, shapes, and vector drawings that can be rendered by Flutter.

This class provides a series of methods for drawing various shapes, setting fill and stroke styles, applying gradients, and applying masks. It also supports hit testing and retrieving the bounding boxes of the drawn shapes. It should not be instantiated, use a GShape.graphics or GSprite.graphics instead

Mixed in types

Constructors

Graphics()

Properties

alpha double
The global alpha value for the graphics object, ranging from 0 to 1.
getter/setter pair
drawingQueue List<GraphicsDrawingData?>
Returns the drawing queue as a list of GraphicsDrawingData?.
no setter
hashCode int
The hash code for this object.
no setterinherited
isMask bool
A flag to indicate whether this object is a mask.
getter/setter pair
mask Graphics?
The Graphics object used as a mask for this object.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

arc(double cx, double cy, double radius, double startAngle, double sweepAngle, [bool moveTo = false]) Graphics
Draws an arc of a circle.
arcOval(double cx, double cy, double radiusX, double radiusY, double startAngle, double sweepAngle) Graphics
Draws an arc of an oval.
arcToPoint(double endX, double endY, double radius, [double rotation = 0.0, bool largeArc = false, bool clockwise = true, bool relativeMoveTo = false]) Graphics
Draws an arc from the current point to a given point.
beginBitmapFill(GTexture texture, [GMatrix? matrix, bool repeat = false, bool smooth = false]) Graphics
Begins filling a shape with the specified bitmap texture.
beginFill(Color color, [bool antiAlias = true]) Graphics
Begins filling a shape with the specified color.
beginGradientFill(GradientType type, List<Color> colors, {List<double>? ratios, Alignment? begin, Alignment? end, double rotation = 0, TileMode tileMode = TileMode.clamp, Rect? gradientBox, double radius = 0.5, double focalRadius = 0.0, double sweepStartAngle = 0.0, double sweepEndAngle = 6.2832}) Graphics
Begins filling a shape with the specified gradient.
beginHole() Graphics
Set the graphics object into a "hole mode". All subsequent shapes will be treated as holes instead of being filled with the current paint. Call endHole to exit hole mode.
beginPaint(Paint paint) Graphics
Begins filling a shape with the specified raw paint instance.
beginShader(Shader shader) Graphics
Begins filling a shape with the specified shader.
blendMode(BlendMode blendMode) Graphics
Applies blendMode to the current drawing fill (or stroke).
clear() Graphics
Removes all strokes and fills.
closePath() Graphics
Closes the current sub-path by drawing a straight line to the starting point of the sub-path.
colorize(Color color) → void
Quick way to colorize all previous drawing. Applies a color filter to all fills in the drawingQueue.
conicCurveTo(double controlX, double controlY, double anchorX, double anchorY, double weight, [bool relative = false]) Graphics
Draws a conic Bezier curve from the current drawing position to the specified anchor point (anchorX, anchorY), using the specified control point(controlX, controlY) and weight.
copyFrom(Graphics other, [bool deepClone = false]) → void
Copies the drawing data from the other, Graphics object.
createImage([bool adjustOffset = true, double resolution = 1]) Future<Image>
Creates an Image object from the rendered image of the object asynchronously. You can optionally provide a resolution value, which defaults to 1.
inherited
createImageSync([bool adjustOffset = true, double resolution = 1]) Image
Creates an Image object from the rendered image of the object synchronously. You can optionally provide a resolution value, which defaults to 1.
inherited
createImageTexture([bool adjustOffset = true, double resolution = 1]) Future<GTexture>
Creates a GTexture object from the rendered image of the object asynchronously. You can optionally provide a resolution value, which defaults to 1.
inherited
createImageTextureSync([bool adjustOffset = true, double resolution = 1]) GTexture
Creates a GTexture object from the rendered image of the object synchronously. You can optionally provide a resolution value, which defaults to 1.
inherited
createPicture([void prePaintCallback(Canvas)?]) Picture
Creates a Picture object and returns it. You can optionally provide a prePaintCallback function that is called before the picture is painted.
inherited
cubicCurveTo(double controlX1, double controlY1, double controlX2, double controlY2, double anchorX, double anchorY) Graphics
anchor point (anchorX, anchorY), using the specified control points (controlX1, controlY1) and (controlX2, controlY2).
curveTo(double controlX, double controlY, double anchorX, double anchorY) Graphics
Draws a quadratic Bezier curve from the current drawing position to the specified anchor point (anchorX, anchorY), using the specified control point (controlX, controlY).
dispose() → void
Disposes the graphics object, clearing the drawing queue and mask.
drawCircle(double x, double y, double radius) Graphics
Draws a circle with the given radius centered at (x, y).
drawEllipse(double x, double y, double radiusX, double radiusY) Graphics
Draws an ellipse centered at the specified coordinates and with the given radii.
drawGRect(GRect rect) Graphics
Draws a rectangle using the specified GRect.
drawPath(Path path, [double x = 0, double y = 0, GMatrix? transform]) Graphics
Appends a native path to the current drawing path, as x and y can offset the target position, while transform can be used to rotated, scale, translate, the given shape.
drawPicture(Picture picture) Graphics
Adds a picture to the list of drawings commands to render.
drawPoly(List<GPoint> points, [bool closePolygon = true]) Graphics
Draws a complex polygon from a List of points that contains the vertices of the polygon Is similar to use moveTo and lineTo methods but in one command. closePolygon will close the shape, defaults to true.
drawPolygonFaces(double x, double y, double radius, int sides, [double rotation = 0]) Graphics
Draws a polygon with faces of equal size from the center point (x, y) to the circumference with a specified number of sides. The radius of the polygon can also be specified, along with an optional rotation angle.
drawRect(double x, double y, double width, double height) Graphics
Draws a rectangle using the specified coordinates and dimensions.
drawRoundRect(double x, double y, double width, double height, double ellipseWidth, [double? ellipseHeight]) Graphics
Draws a rounded rectangle with the same radius on all corners.
drawRoundRectComplex(double x, double y, double width, double height, [double topLeftRadius = 0, double topRightRadius = 0, double bottomLeftRadius = 0, double bottomRightRadius = 0]) Graphics
Draws a rounded rectangle with different corner radii.
drawStar(double x, double y, int points, double radius, [double? innerRadius, double rotation = 0]) Graphics
Draws a star polygon with a given number of points and radius from the center point (x, y). An optional innerRadius can be specified to create a star shape. The star can also be rotated by rotation angle (defaults to 0).
drawTriangles(List<double> vertices, [List<int>? indices, List<double>? uvtData, List<int>? hexColors, BlendMode? blendMode = BlendMode.src, Culling culling = Culling.positive]) Graphics
(Warning: Experimental and buggy)
endFill() Graphics
Ends the current fill.
endHole([bool applyToCurrentQueue = false]) Graphics
Finishes the current beginHole command. When applyToCurrentQueue is true, the drawing commands of the "hole" will be applied to the current elements of the drawing queue (not including future ones), when applyToCurrentQueue is false, it will only cut the "holes" in the last drawing command.
getAllBounds([List<GRect>? out]) List<GRect>
Returns a list of all bounding boxes of the drawn shapes.
getBounds([GRect? out]) GRect
Returns the bounding box of the graphics object.
override
getPaths() Path
Returns the combined path of all the graphics in the drawing queue.
hitTest(GPoint localPoint, [bool useShape = false]) bool
Determines whether the given localPoint is within the bounds of this Graphics object.
lineBitmapStyle(GTexture texture, [GMatrix? matrix, bool repeat = true, bool smooth = false]) Graphics
Sets the bitmap for drawing strokes. Use after lineStyle() to apply an image shader into the current Paint.
lineGradientStyle(GradientType type, List<Color> colors, {List<double>? ratios, Alignment? begin, Alignment? end, double rotation = 0, double radius = 0.5, double focalRadius = 0.0, double sweepStartAngle = 0.0, double sweepEndAngle = 6.2832, Rect? gradientBox, TileMode tileMode = TileMode.clamp}) Graphics
Sets the gradient type for drawing strokes. Uses a gradient shader for the current lineStyle, so is mandatory to have a lineStyle before calling this method.
lineShaderStyle(Shader shader) Graphics
Sets the shader for drawing strokes. Use after lineStyle to apply a shader into the current Paint.
lineStyle([double thickness = 0.0, Color color = kColorBlack, bool pixelHinting = true, StrokeCap? caps, StrokeJoin? joints, double miterLimit = 3.0]) Graphics
Sets the line style for drawing strokes.
lineTo(double x, double y) Graphics
Draws a straight line from the current drawing position to the specified coordinates using a line segment.
moveTo(double x, double y) Graphics
Moves the current drawing position to the specified x and y coordinates.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
paint(Canvas canvas) → void
(Internal usage) Paints the graphics onto the given Canvas. If isMask is true, it clips the canvas to the path of each GraphicsDrawingData in the _drawingQueue, allowing for masking effects. Otherwise, it iterates over each GraphicsDrawingData in the _drawingQueue and draws its path or picture onto the canvas, filling it with the corresponding Paint. If the GraphicsDrawingData contains a gradient, it calculates the gradient's bounds and creates a shader from the gradient to fill the shape. If the GraphicsDrawingData contains vertices, it draws them onto the canvas using the corresponding Paint. If the GraphicsDrawingData contains a picture, it draws the picture onto the canvas.
override
paintWithFill(Canvas canvas, Paint fill) → void
Paints the graphics with the specified fill on the given canvas.
popData() GraphicsDrawingData?
Removes the last GraphicsDrawingData from the drawing queue. This should be used only if you are operating with Path and Paint directly.
pushData(GraphicsDrawingData data, [bool asCurrent = false, double? x, double? y]) → void
Push a GraphicsDrawingData into the commands list. This way you can use the low level APIs as you please. When set asCurrent to true, it will be used as the current GraphicsDrawingData and you can keep modifying the internal path with Graphics commands. This should be used only if you are operating with Path and Paint directly. x and y can shift the Path coordinates.
removeData(GraphicsDrawingData data) → void
Removes, if enqueued, the specified GraphicsDrawingData instance from the drawing queue list. This should be used only if you are operating with Path and Paint directly.
shiftPath(double x, double y, [bool modifyPreviousPaths = false]) → void
Shifts the current path by a given offset x, y.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

stageRectPath Path
(Internal usage) Utility method to get the path representing the stage rectangle.
final

Static Methods

updateStageRect(GRect rect) → void
(Internal usage) Updates the stage rectangle path with the given rect.