Skip to content

CanvasRenderingContext2D ​

class CanvasRenderingContext2D extends JavaScriptObject implements CanvasRenderingContext

Annotations: @Native.new("CanvasRenderingContext2D")

Implemented types

Properties ​

deprecated backingStorePixelRatio no setter ​

double get backingStorePixelRatio

DEPRECATED

Deprecated always returns 1.0

Implementation
dart
@deprecated
double get backingStorePixelRatio => 1.0;

canvas no setter override ​

CanvasElement get canvas
Implementation
dart
CanvasElement get canvas native;

currentTransform read / write ​

Matrix? get currentTransform
Implementation
dart
Matrix? get currentTransform native;

set currentTransform(Matrix? value) native;

direction read / write ​

String? get direction
Implementation
dart
String? get direction native;

set direction(String? value) native;

fillStyle read / write ​

Object? get fillStyle
Implementation
dart
@Creates('String|CanvasGradient|CanvasPattern')
@Returns('String|CanvasGradient|CanvasPattern')
Object? get fillStyle native;

set fillStyle(Object? value) native;

filter read / write ​

String? get filter
Implementation
dart
String? get filter native;

set filter(String? value) native;

font read / write ​

String get font
Implementation
dart
String get font native;

set font(String value) native;

globalAlpha read / write ​

num get globalAlpha
Implementation
dart
num get globalAlpha native;

set globalAlpha(num value) native;

globalCompositeOperation read / write ​

String get globalCompositeOperation
Implementation
dart
String get globalCompositeOperation native;

set globalCompositeOperation(String value) native;

hashCode no setter inherited ​

int get hashCode

Inherited from Interceptor.

Implementation
dart
int get hashCode => Primitives.objectHashCode(this);

imageSmoothingEnabled read / write ​

bool? get imageSmoothingEnabled

Whether images and patterns on this canvas will be smoothed when this canvas is scaled.

Other resources ​

Implementation
dart
bool? get imageSmoothingEnabled native;

set imageSmoothingEnabled(bool? value) native;

imageSmoothingQuality read / write ​

String? get imageSmoothingQuality
Implementation
dart
String? get imageSmoothingQuality native;

set imageSmoothingQuality(String? value) native;

lineCap read / write ​

String get lineCap
Implementation
dart
String get lineCap native;

set lineCap(String value) native;

lineDashOffset read / write ​

num get lineDashOffset
Implementation
dart
@SupportedBrowser(SupportedBrowser.CHROME)
@SupportedBrowser(SupportedBrowser.SAFARI)
@SupportedBrowser(SupportedBrowser.IE, '11')
@Unstable()
// TODO(14316): Firefox has this functionality with mozDashOffset, but it
// needs to be polyfilled.
num get lineDashOffset =>
    JS('num', '#.lineDashOffset || #.webkitLineDashOffset', this, this);

@SupportedBrowser(SupportedBrowser.CHROME)
@SupportedBrowser(SupportedBrowser.SAFARI)
@SupportedBrowser(SupportedBrowser.IE, '11')
@Unstable()
// TODO(14316): Firefox has this functionality with mozDashOffset, but it
// needs to be polyfilled.
set lineDashOffset(num value) {
  JS(
    'void',
    'typeof #.lineDashOffset != "undefined" ? #.lineDashOffset = # : '
        '#.webkitLineDashOffset = #',
    this,
    this,
    value,
    this,
    value,
  );
}

lineJoin read / write ​

String get lineJoin
Implementation
dart
String get lineJoin native;

set lineJoin(String value) native;

lineWidth read / write ​

num get lineWidth
Implementation
dart
num get lineWidth native;

set lineWidth(num value) native;

miterLimit read / write ​

num get miterLimit
Implementation
dart
num get miterLimit native;

set miterLimit(num value) native;

runtimeType no setter inherited ​

Type get runtimeType

Inherited from Interceptor.

Implementation
dart
Type get runtimeType =>
    getRuntimeTypeOfInterceptorNotArray(getInterceptor(this), this);

shadowBlur read / write ​

num get shadowBlur
Implementation
dart
num get shadowBlur native;

set shadowBlur(num value) native;

shadowColor read / write ​

String get shadowColor
Implementation
dart
String get shadowColor native;

set shadowColor(String value) native;

shadowOffsetX read / write ​

num get shadowOffsetX
Implementation
dart
num get shadowOffsetX native;

set shadowOffsetX(num value) native;

shadowOffsetY read / write ​

num get shadowOffsetY
Implementation
dart
num get shadowOffsetY native;

set shadowOffsetY(num value) native;

strokeStyle read / write ​

Object? get strokeStyle
Implementation
dart
@Creates('String|CanvasGradient|CanvasPattern')
@Returns('String|CanvasGradient|CanvasPattern')
Object? get strokeStyle native;

set strokeStyle(Object? value) native;

textAlign read / write ​

String get textAlign
Implementation
dart
String get textAlign native;

set textAlign(String value) native;

textBaseline read / write ​

String get textBaseline
Implementation
dart
String get textBaseline native;

set textBaseline(String value) native;

Methods ​

addHitRegion() ​

void addHitRegion([Map<dynamic, dynamic>? options])
Implementation
dart
void addHitRegion([Map? options]) {
  if (options != null) {
    var options_1 = convertDartToNative_Dictionary(options);
    _addHitRegion_1(options_1);
    return;
  }
  _addHitRegion_2();
  return;
}

arc() ​

void arc(
  num x,
  num y,
  num radius,
  num startAngle,
  num endAngle, [
  bool anticlockwise = false,
])
Implementation
dart
void arc(
  num x,
  num y,
  num radius,
  num startAngle,
  num endAngle, [
  bool anticlockwise = false,
]) {
  &#47;&#47; TODO(terry): This should not be needed: dartbug.com&#47;20939.
  JS(
    'void',
    '#.arc(#, #, #, #, #, #)',
    this,
    x,
    y,
    radius,
    startAngle,
    endAngle,
    anticlockwise,
  );
}

arcTo() ​

void arcTo(num x1, num y1, num x2, num y2, num radius)
Implementation
dart
void arcTo(num x1, num y1, num x2, num y2, num radius) native;

beginPath() ​

void beginPath()
Implementation
dart
void beginPath() native;

bezierCurveTo() ​

void bezierCurveTo(num cp1x, num cp1y, num cp2x, num cp2y, num x, num y)
Implementation
dart
void bezierCurveTo(
  num cp1x,
  num cp1y,
  num cp2x,
  num cp2y,
  num x,
  num y,
) native;

clearHitRegions() ​

void clearHitRegions()
Implementation
dart
void clearHitRegions() native;

clearRect() ​

void clearRect(num x, num y, num width, num height)
Implementation
dart
void clearRect(num x, num y, num width, num height) native;

clip() ​

void clip([dynamic path_OR_winding, String? winding])
Implementation
dart
void clip([path_OR_winding, String? winding]) native;

closePath() ​

void closePath()
Implementation
dart
void closePath() native;

createImageData() ​

ImageData createImageData(
  dynamic data_OR_imagedata_OR_sw, [
  int? sh_OR_sw,
  dynamic imageDataColorSettings_OR_sh,
  Map<dynamic, dynamic>? imageDataColorSettings,
])
Implementation
dart
@Creates('ImageData|=Object')
ImageData createImageData(
  data_OR_imagedata_OR_sw, [
  int? sh_OR_sw,
  imageDataColorSettings_OR_sh,
  Map? imageDataColorSettings,
]) {
  if ((data_OR_imagedata_OR_sw is ImageData) &&
      sh_OR_sw == null &&
      imageDataColorSettings_OR_sh == null &&
      imageDataColorSettings == null) {
    var imagedata_1 = convertDartToNative_ImageData(data_OR_imagedata_OR_sw);
    return convertNativeToDart_ImageData(_createImageData_1(imagedata_1));
  }
  if (sh_OR_sw != null &&
      (data_OR_imagedata_OR_sw is int) &&
      imageDataColorSettings_OR_sh == null &&
      imageDataColorSettings == null) {
    return convertNativeToDart_ImageData(
      _createImageData_2(data_OR_imagedata_OR_sw, sh_OR_sw),
    );
  }
  if ((imageDataColorSettings_OR_sh is Map) &&
      sh_OR_sw != null &&
      (data_OR_imagedata_OR_sw is int) &&
      imageDataColorSettings == null) {
    var imageDataColorSettings_1 = convertDartToNative_Dictionary(
      imageDataColorSettings_OR_sh,
    );
    return convertNativeToDart_ImageData(
      _createImageData_3(
        data_OR_imagedata_OR_sw,
        sh_OR_sw,
        imageDataColorSettings_1,
      ),
    );
  }
  if ((imageDataColorSettings_OR_sh is int) &&
      sh_OR_sw != null &&
      data_OR_imagedata_OR_sw != null &&
      imageDataColorSettings == null) {
    return convertNativeToDart_ImageData(
      _createImageData_4(
        data_OR_imagedata_OR_sw,
        sh_OR_sw,
        imageDataColorSettings_OR_sh,
      ),
    );
  }
  if (imageDataColorSettings != null &&
      (imageDataColorSettings_OR_sh is int) &&
      sh_OR_sw != null &&
      data_OR_imagedata_OR_sw != null) {
    var imageDataColorSettings_1 = convertDartToNative_Dictionary(
      imageDataColorSettings,
    );
    return convertNativeToDart_ImageData(
      _createImageData_5(
        data_OR_imagedata_OR_sw,
        sh_OR_sw,
        imageDataColorSettings_OR_sh,
        imageDataColorSettings_1,
      ),
    );
  }
  throw new ArgumentError("Incorrect number or type of arguments");
}

createImageDataFromImageData() ​

ImageData createImageDataFromImageData(ImageData imagedata)
Implementation
dart
ImageData createImageDataFromImageData(ImageData imagedata) =>
    JS('ImageData', '#.createImageData(#)', this, imagedata);

createLinearGradient() ​

CanvasGradient createLinearGradient(num x0, num y0, num x1, num y1)
Implementation
dart
CanvasGradient createLinearGradient(num x0, num y0, num x1, num y1) native;

createPattern() ​

CanvasPattern? createPattern(Object image, String repetitionType)
Implementation
dart
CanvasPattern? createPattern(Object image, String repetitionType) native;

createPatternFromImage() ​

CanvasPattern createPatternFromImage(ImageElement image, String repetitionType)
Implementation
dart
CanvasPattern createPatternFromImage(
  ImageElement image,
  String repetitionType,
) =>
    JS('CanvasPattern', '#.createPattern(#, #)', this, image, repetitionType);

createRadialGradient() ​

CanvasGradient createRadialGradient(
  num x0,
  num y0,
  num r0,
  num x1,
  num y1,
  num r1,
)
Implementation
dart
CanvasGradient createRadialGradient(
  num x0,
  num y0,
  num r0,
  num x1,
  num y1,
  num r1,
) native;

drawFocusIfNeeded() ​

void drawFocusIfNeeded(dynamic element_OR_path, [Element? element])
Implementation
dart
void drawFocusIfNeeded(element_OR_path, [Element? element]) native;

drawImage() ​

void drawImage(CanvasImageSource source, num destX, num destY)

Draws an image from a CanvasImageSource to this canvas.

The entire image from source will be drawn to this context with its top left corner at the point (destX, destY). If the image is larger than canvas will allow, the image will be clipped to fit the available space.

dart
CanvasElement canvas = new CanvasElement(width: 600, height: 600);
CanvasRenderingContext2D ctx = canvas.context2D;
ImageElement img = document.query('img');

ctx.drawImage(img, 100, 100);

VideoElement video = document.query('video');
ctx.drawImage(video, 0, 0);

CanvasElement otherCanvas = document.query('canvas');
otherCanvas.width = 100;
otherCanvas.height = 100;
ctx.drawImage(otherCanvas, 590, 590); // will get clipped

See also:

Implementation
dart
@JSName('drawImage')
void drawImage(CanvasImageSource source, num destX, num destY) native;

drawImageScaled() ​

void drawImageScaled(
  CanvasImageSource source,
  num destX,
  num destY,
  num destWidth,
  num destHeight,
)

Draws an image from a CanvasImageSource to an area of this canvas.

The image will be drawn to this context with its top left corner at the point (destX, destY) and will be scaled to be destWidth wide and destHeight tall.

If the image is larger than canvas will allow, the image will be clipped to fit the available space.

dart
CanvasElement canvas = new CanvasElement(width: 600, height: 600);
CanvasRenderingContext2D ctx = canvas.context2D;
ImageElement img = document.query('img');
img.width = 100;
img.height = 100;

// Scale the image to 300x50 at the point (20, 20)
ctx.drawImageScaled(img, 20, 20, 300, 50);

See also:

Implementation
dart
@JSName('drawImage')
void drawImageScaled(
  CanvasImageSource source,
  num destX,
  num destY,
  num destWidth,
  num destHeight,
) native;

drawImageScaledFromSource() ​

void drawImageScaledFromSource(
  CanvasImageSource source,
  num sourceX,
  num sourceY,
  num sourceWidth,
  num sourceHeight,
  num destX,
  num destY,
  num destWidth,
  num destHeight,
)

Draws an image from a CanvasImageSource to an area of this canvas.

The image is a region of source that is sourceWidth wide and sourceHeight tall with top left corner at (sourceX, sourceY). The image will be drawn to this context with its top left corner at the point (destX, destY) and will be scaled to be destWidth wide and destHeight tall.

If the image is larger than canvas will allow, the image will be clipped to fit the available space.

dart
VideoElement video = document.query('video');
video.width = 100;
video.height = 100;
// Take the middle 20x20 pixels from the video and stretch them.
ctx.drawImageScaledFromSource(video, 40, 40, 20, 20, 50, 50, 100, 100);

// Draw the top 100x20 pixels from the otherCanvas to this one.
CanvasElement otherCanvas = document.query('canvas');
ctx.drawImageScaledFromSource(otherCanvas, 0, 0, 100, 20, 0, 0, 100, 20);

See also:

Implementation
dart
@JSName('drawImage')
void drawImageScaledFromSource(
  CanvasImageSource source,
  num sourceX,
  num sourceY,
  num sourceWidth,
  num sourceHeight,
  num destX,
  num destY,
  num destWidth,
  num destHeight,
) native;

drawImageToRect() ​

void drawImageToRect(
  CanvasImageSource source,
  Rectangle<num> destRect, {
  Rectangle<num>? sourceRect,
})

Draws an image from a CanvasImageSource to an area of this canvas.

The image will be drawn to an area of this canvas defined by destRect. sourceRect defines the region of the source image that is drawn. If sourceRect is not provided, then the entire rectangular image from source will be drawn to this context.

If the image is larger than canvas will allow, the image will be clipped to fit the available space.

dart
CanvasElement canvas = new CanvasElement(width: 600, height: 600);
CanvasRenderingContext2D ctx = canvas.context2D;
ImageElement img = document.query('img');
img.width = 100;
img.height = 100;

// Scale the image to 20x20.
ctx.drawImageToRect(img, new Rectangle(50, 50, 20, 20));

VideoElement video = document.query('video');
video.width = 100;
video.height = 100;
// Take the middle 20x20 pixels from the video and stretch them.
ctx.drawImageToRect(video, new Rectangle(50, 50, 100, 100),
    sourceRect: new Rectangle(40, 40, 20, 20));

// Draw the top 100x20 pixels from the otherCanvas.
CanvasElement otherCanvas = document.query('canvas');
ctx.drawImageToRect(otherCanvas, new Rectangle(0, 0, 100, 20),
    sourceRect: new Rectangle(0, 0, 100, 20));

See also:

Implementation
dart
void drawImageToRect(
  CanvasImageSource source,
  Rectangle destRect, {
  Rectangle? sourceRect,
}) {
  if (sourceRect == null) {
    drawImageScaled(
      source,
      destRect.left,
      destRect.top,
      destRect.width,
      destRect.height,
    );
  } else {
    drawImageScaledFromSource(
      source,
      sourceRect.left,
      sourceRect.top,
      sourceRect.width,
      sourceRect.height,
      destRect.left,
      destRect.top,
      destRect.width,
      destRect.height,
    );
  }
}

ellipse() ​

void ellipse(
  num x,
  num y,
  num radiusX,
  num radiusY,
  num rotation,
  num startAngle,
  num endAngle,
  bool? anticlockwise,
)
Implementation
dart
void ellipse(
  num x,
  num y,
  num radiusX,
  num radiusY,
  num rotation,
  num startAngle,
  num endAngle,
  bool? anticlockwise,
) native;

fill() ​

void fill([dynamic path_OR_winding, String? winding])
Implementation
dart
void fill([path_OR_winding, String? winding]) native;

fillRect() ​

void fillRect(num x, num y, num width, num height)
Implementation
dart
void fillRect(num x, num y, num width, num height) native;

fillText() ​

void fillText(String text, num x, num y, [num? maxWidth])

Draws text to the canvas.

The text is drawn starting at coordinates (x, y). If maxWidth is provided and the text is computed to be wider than maxWidth, then the drawn text is scaled down horizontally to fit.

The text uses the current CanvasRenderingContext2D.font property for font options, such as typeface and size, and the current CanvasRenderingContext2D.fillStyle for style options such as color. The current CanvasRenderingContext2D.textAlign and CanvasRenderingContext2D.textBaseline properties are also applied to the drawn text.

Implementation
dart
void fillText(String text, num x, num y, [num? maxWidth]) {
  if (maxWidth != null) {
    JS('void', '#.fillText(#, #, #, #)', this, text, x, y, maxWidth);
  } else {
    JS('void', '#.fillText(#, #, #)', this, text, x, y);
  }
}

getContextAttributes() ​

Map<dynamic, dynamic> getContextAttributes()
Implementation
dart
Map getContextAttributes() {
  return convertNativeToDart_Dictionary(_getContextAttributes_1())!;
}

getImageData() ​

ImageData getImageData(int sx, int sy, int sw, int sh)
Implementation
dart
@Creates('ImageData|=Object')
ImageData getImageData(int sx, int sy, int sw, int sh) {
  return convertNativeToDart_ImageData(_getImageData_1(sx, sy, sw, sh));
}

getLineDash() ​

List<num> getLineDash()
Implementation
dart
@SupportedBrowser(SupportedBrowser.CHROME)
@SupportedBrowser(SupportedBrowser.SAFARI)
@SupportedBrowser(SupportedBrowser.IE, '11')
@Unstable()
List<num> getLineDash() {
  &#47;&#47; TODO(14316): Firefox has this functionality with mozDash, but it's a bit
  &#47;&#47; different.
  if (JS('bool', '!!#.getLineDash', this)) {
    return JS('List<num>', '#.getLineDash()', this);
  } else if (JS('bool', '!!#.webkitLineDash', this)) {
    return JS('List<num>', '#.webkitLineDash', this);
  }
  return [];
}

isContextLost() ​

bool isContextLost()
Implementation
dart
bool isContextLost() native;

isPointInPath() ​

bool isPointInPath(
  dynamic path_OR_x,
  num x_OR_y, [
  dynamic winding_OR_y,
  String? winding,
])
Implementation
dart
bool isPointInPath(
  path_OR_x,
  num x_OR_y, [
  winding_OR_y,
  String? winding,
]) native;

isPointInStroke() ​

bool isPointInStroke(dynamic path_OR_x, num x_OR_y, [num? y])
Implementation
dart
bool isPointInStroke(path_OR_x, num x_OR_y, [num? y]) native;

lineTo() ​

void lineTo(num x, num y)
Implementation
dart
void lineTo(num x, num y) native;

measureText() ​

TextMetrics measureText(String text)
Implementation
dart
TextMetrics measureText(String text) native;

moveTo() ​

void moveTo(num x, num y)
Implementation
dart
void moveTo(num x, num y) native;

noSuchMethod() inherited ​

dynamic noSuchMethod(Invocation invocation)

Invoked when a nonexistent method or property is accessed.

A dynamic member invocation can attempt to call a member which doesn't exist on the receiving object. Example:

dart
dynamic object = 1;
object.add(42); // Statically allowed, run-time error

This invalid code will invoke the noSuchMethod method of the integer 1 with an Invocation representing the .add(42) call and arguments (which then throws).

Classes can override noSuchMethod to provide custom behavior for such invalid dynamic invocations.

A class with a non-default noSuchMethod invocation can also omit implementations for members of its interface. Example:

dart
class MockList<T> implements List<T> {
  noSuchMethod(Invocation invocation) {
    log(invocation);
    super.noSuchMethod(invocation); // Will throw.
  }
}
void main() {
  MockList().add(42);
}

This code has no compile-time warnings or errors even though the MockList class has no concrete implementation of any of the List interface methods. Calls to List methods are forwarded to noSuchMethod, so this code will log an invocation similar to Invocation.method(#add, [42]) and then throw.

If a value is returned from noSuchMethod, it becomes the result of the original invocation. If the value is not of a type that can be returned by the original invocation, a type error occurs at the invocation.

The default behavior is to throw a NoSuchMethodError.

Inherited from Interceptor.

Implementation
dart
dynamic noSuchMethod(Invocation invocation) {
  throw NoSuchMethodError.withInvocation(this, invocation);
}

putImageData() ​

void putImageData(
  ImageData imagedata,
  int dx,
  int dy, [
  int? dirtyX,
  int? dirtyY,
  int? dirtyWidth,
  int? dirtyHeight,
])
Implementation
dart
void putImageData(
  ImageData imagedata,
  int dx,
  int dy, [
  int? dirtyX,
  int? dirtyY,
  int? dirtyWidth,
  int? dirtyHeight,
]) {
  if (dirtyX == null &&
      dirtyY == null &&
      dirtyWidth == null &&
      dirtyHeight == null) {
    var imagedata_1 = convertDartToNative_ImageData(imagedata);
    _putImageData_1(imagedata_1, dx, dy);
    return;
  }
  if (dirtyHeight != null &&
      dirtyWidth != null &&
      dirtyY != null &&
      dirtyX != null) {
    var imagedata_1 = convertDartToNative_ImageData(imagedata);
    _putImageData_2(
      imagedata_1,
      dx,
      dy,
      dirtyX,
      dirtyY,
      dirtyWidth,
      dirtyHeight,
    );
    return;
  }
  throw new ArgumentError("Incorrect number or type of arguments");
}

quadraticCurveTo() ​

void quadraticCurveTo(num cpx, num cpy, num x, num y)
Implementation
dart
void quadraticCurveTo(num cpx, num cpy, num x, num y) native;

rect() ​

void rect(num x, num y, num width, num height)
Implementation
dart
void rect(num x, num y, num width, num height) native;

removeHitRegion() ​

void removeHitRegion(String id)
Implementation
dart
void removeHitRegion(String id) native;

resetTransform() ​

void resetTransform()
Implementation
dart
void resetTransform() native;

restore() ​

void restore()
Implementation
dart
void restore() native;

rotate() ​

void rotate(num angle)
Implementation
dart
void rotate(num angle) native;

save() ​

void save()
Implementation
dart
void save() native;

scale() ​

void scale(num x, num y)
Implementation
dart
void scale(num x, num y) native;

scrollPathIntoView() ​

void scrollPathIntoView([Path2D? path])
Implementation
dart
void scrollPathIntoView([Path2D? path]) native;

setFillColorHsl() ​

void setFillColorHsl(int h, num s, num l, [num a = 1])

Sets the color used inside shapes. h is in degrees, 0-360. s, l are in percent, 0-100. a is 0-1.

Implementation
dart
void setFillColorHsl(int h, num s, num l, [num a = 1]) {
  this.fillStyle = 'hsla($h, $s%, $l%, $a)';
}

setFillColorRgb() ​

void setFillColorRgb(int r, int g, int b, [num a = 1])

Sets the color used inside shapes. r, g, b are 0-255, a is 0-1.

Implementation
dart
void setFillColorRgb(int r, int g, int b, [num a = 1]) {
  this.fillStyle = 'rgba($r, $g, $b, $a)';
}

setLineDash() ​

void setLineDash(List<num> dash)
Implementation
dart
@SupportedBrowser(SupportedBrowser.CHROME)
@SupportedBrowser(SupportedBrowser.SAFARI)
@SupportedBrowser(SupportedBrowser.IE, '11')
@Unstable()
void setLineDash(List<num> dash) {
  &#47;&#47; TODO(14316): Firefox has this functionality with mozDash, but it's a bit
  &#47;&#47; different.
  if (JS('bool', '!!#.setLineDash', this)) {
    JS('void', '#.setLineDash(#)', this, dash);
  } else if (JS('bool', '!!#.webkitLineDash', this)) {
    JS('void', '#.webkitLineDash = #', this, dash);
  }
}

setStrokeColorHsl() ​

void setStrokeColorHsl(int h, num s, num l, [num a = 1])

Sets the color used for stroking shapes. h is in degrees, 0-360. s, l are in percent, 0-100. a is 0-1.

Implementation
dart
void setStrokeColorHsl(int h, num s, num l, [num a = 1]) {
  this.strokeStyle = 'hsla($h, $s%, $l%, $a)';
}

setStrokeColorRgb() ​

void setStrokeColorRgb(int r, int g, int b, [num a = 1])

Sets the color used for stroking shapes. r, g, b are 0-255, a is 0-1.

Implementation
dart
void setStrokeColorRgb(int r, int g, int b, [num a = 1]) {
  this.strokeStyle = 'rgba($r, $g, $b, $a)';
}

setTransform() ​

void setTransform(num a, num b, num c, num d, num e, num f)
Implementation
dart
void setTransform(num a, num b, num c, num d, num e, num f) native;

stroke() ​

void stroke([Path2D? path])
Implementation
dart
void stroke([Path2D? path]) native;

strokeRect() ​

void strokeRect(num x, num y, num width, num height)
Implementation
dart
void strokeRect(num x, num y, num width, num height) native;

strokeText() ​

void strokeText(String text, num x, num y, [num? maxWidth])
Implementation
dart
void strokeText(String text, num x, num y, [num? maxWidth]) native;

toString() inherited ​

String toString()

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Inherited from Interceptor.

Implementation
dart
String toString() => Primitives.objectToHumanReadableString(this);

transform() ​

void transform(num a, num b, num c, num d, num e, num f)
Implementation
dart
void transform(num a, num b, num c, num d, num e, num f) native;

translate() ​

void translate(num x, num y)
Implementation
dart
void translate(num x, num y) native;

Operators ​

operator ==() inherited ​

bool operator ==(Object other)

The equality operator.

The default behavior for all Objects is to return true if and only if this object and other are the same object.

Override this method to specify a different equality relation on a class. The overriding method must still be an equivalence relation. That is, it must be:

  • Total: It must return a boolean for all arguments. It should never throw.

  • Reflexive: For all objects o, o == o must be true.

  • Symmetric: For all objects o1 and o2, o1 == o2 and o2 == o1 must either both be true, or both be false.

  • Transitive: For all objects o1, o2, and o3, if o1 == o2 and o2 == o3 are true, then o1 == o3 must be true.

The method should also be consistent over time, so whether two objects are equal should only change if at least one of the objects was modified.

If a subclass overrides the equality operator, it should override the hashCode method as well to maintain consistency.

Inherited from Interceptor.

Implementation
dart
bool operator ==(Object other) => identical(this, other);