PreviewCanvas class

The devices one subtree of a package is meant to be seen on.

// demo/lib/canvases.dart — no Flutter import, so `tool/flutterware.dart`
// can read it under a plain `dart run` and a test can read it too.
const canvases = [
  PreviewCanvas('src/mobile', devices: [Devices.iphone16, Devices.iphoneSe]),
  PreviewCanvas('src/desktop', devices: [Devices.window, Devices.wideWindow]),
];

The two lines read differently on purpose, and defaultDevice is where the difference lives: the mobile entries open on an iPhone 16, and the desktop ones open on the plain resizable rectangle with those two window sizes offered beside it.

Named PreviewCanvas rather than Canvas because of dart:ui. A test importing package:flutterware/flutter_test.dart has Flutter's Canvas in scope through package:flutter_test, and two exported Canvases are an ambiguous name in every file that imports both — which is precisely the file this type exists to serve.

Constructors

PreviewCanvas(String prefix, {List<Device> devices = const [], List<ScreenOrientation> orientations = const [], List<KeyboardMode> keyboards = const []})
const

Properties

defaultDevice → Device?
What one picture of an entry under this canvas is framed as.
no setter
defaultKeyboard → KeyboardMode?
And whether it has a keyboard over it.
no setter
defaultOrientation → ScreenOrientation?
Which way up that picture is.
no setter
devices → List<Device>
The devices these entries are worth looking at on.
final
hashCode → int
The hash code for this object.
no setterinherited
keyboards → List<KeyboardMode>
Whether the entries under here are worth seeing with a keyboard up, head first, likewise.
final
orientations → List<ScreenOrientation>
The orientations worth crossing devices with, head first, likewise.
final
prefix → String
Which entries this covers: a path relative to the package, in the same coordinates as PreviewsPackage.directory and the paths the tool reports entries under.
final
root → String
prefix with its slashes tidied — no leading or trailing one, . and the empty string both meaning the whole package.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

covers(String path) → bool
Whether path — a package-relative, /-separated file or directory — is under this canvas.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() → Map<String, Object?>
toString() → String
A string representation of this object.
override

Operators

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

Static Methods

fromJson(Object? raw) → PreviewCanvas?
Reads back what toJson wrote.