shutter library
Shutter as a Dart library: shot renders a Flutter project's previews,
or one widget expression, to PNG as a new run, diff compares two
runs, doctor checks what shooting needs, and prune deletes old
runs, as shutter shot, shutter semantics, shutter diff, shutter doctor, and shutter prune do, without starting a process.
import 'package:shutter/shutter.dart';
Future<void> main() async {
final run = await shot(
'/path/to/app',
const PreviewFiles(['lib/preview/notification_tile_preview.dart']),
onProgress: (event) => print(event.message),
);
for (final result in run.shots) {
print('${result.id} ${result.status.name} ${result.png}');
}
}
A shot that fails to render is a ShotStatus.error in the run, and a change between two runs is an entry of the diff; a run that cannot be shot, or runs that cannot be compared, throw a ShutterException.
Classes
- DiffComposite
-
The sheets diff writes, as
shutter diff --composite: one image per entry that has something to show, holding its before, diff, and after panels, to attach on its own. - DoctorCheck
- One line of doctor's report.
- FontsDownloading
- google_fonts files missing from the cache are being downloaded.
- Keyboard
-
An on-screen keyboard to lay the preview out with, as
--keyboard(experimental). The keyboard itself is not drawn. - LogicalSize
-
A size in logical pixels. As the size of a WidgetExpression, the
height may be
double.infinity, as in a preview'sSize(360, double.infinity): the widget is then shot at that width and its own height, as--size <width>x. - PreviewCapture
- The preview alone.
- PreviewFiles
-
The
@Previewfunctions of these files, asshutter shot <file>.... - PruneResult
- The outcome of prune: absolute paths of the run directories, oldest first.
- RenderStarted
-
flutter teststarts rendering every shot. round counts from 1; a later round renders every shot again with the fonts the previous one found missing. - SafeAreaInsets
-
The safe area of the device the app is laid out for, as
--safe-area: the insets of its status bar or notch and of its home indicator, in logical pixels. They are reported to the app as the view padding and not drawn. - ScanStarted
- The preview files are being read for their previews.
- ScreenCapture
- The whole screen: the viewport, with the menus and dialogs the app draws above the preview.
- ShotAction
-
One
shot --tap,--enter,--press,--hover, or--focus. - ShotCapture
-
What a shot's PNG holds, as
--capture. - ShotDiff
- The outcome of diff: the two runs and each shot id across them.
- ShotDiffEntry
- One shot id of a ShotDiff.
- ShotFile
- A file a run read, as its manifest records it.
- ShotProgress
- What a shot run is doing, as it does it; each event's message is a line for a log.
- ShotRendered
-
One shot finished rendering in round; whether it is
okor anerroris known when the run ends. - ShotResult
- One shot of a ShotRun.
- ShotRun
- The outcome of shot: the run directory and each shot in it.
- ShotSetup
- What a run was shot with besides its subject: the arguments of shot its manifest records. Two runs shot with different ones differ in every image without any widget changing.
- ShotSubject
- What a run shoots: the previews of PreviewFiles, or one WidgetExpression.
- ShotTarget
-
The widget an action acts on:
key:<value>,text:<value>,label:<value>, ortype:<value>on the command line. - UnboundedSize
- WidgetSize.unbounded.
- WidgetExpression
-
One widget expression, without a preview file, as
shutter shot --widget. - WidgetSize
- The size of a WidgetExpression: a LogicalSize, or WidgetSize.unbounded.
Enums
- ActionKind
- What an action does to its target before the capture.
- CheckLevel
- How a DoctorCheck came out.
- CompositeDirection
- How the three panels of a composite are laid out.
- DiffStatus
- Classification of one id across two runs, in the order to look at.
- ShotBrightness
-
The platform brightness a run reports to the app (
--brightness); a preview's ownbrightnesswins.flutter testreports light. - ShotPlatform
-
The platform a run draws the app as (
--platform).flutter testdraws as Android unless told otherwise. - ShotStatus
- Outcome of one shot.
- TargetKind
- How an action's target is found.
Functions
-
diff(
String projectDir, String before, String after, {bool images = false, DiffComposite? composite}) → Future< ShotDiff> -
Compares two runs of the Flutter project at or above
projectDirpixel by pixel, by shot id, asshutter diffdoes.beforeandaftereach name a run: a run directory (relative toprojectDir, or absolute) such as ShotRun.dir, a run id,latest, orlatest~Nfor the run N before it. -
doctor(
String projectDir, {String? shell}) → List< DoctorCheck> -
Checks what shooting the Flutter project at or above
projectDirneeds, asshutter doctordoes: the Flutter SDK and its version, its font cache, the project, and its shell,shell(relative toprojectDir, or absolute) when given. Returns the checks in the order of the report; a CheckLevel.fail among them means shot will not work until it is fixed, andshutter doctorexits 1. -
prune(
String projectDir, {required int keep}) → PruneResult -
Deletes every run under
.dart_tool/shutter/runs/of the Flutter project at or aboveprojectDirbut the newestkeep, asshutter prune --keep, whoever shot them. A run still being shot is neither counted nor deleted. Throws a ShutterException whenkeepis negative or no project is found. -
shot(
String projectDir, ShotSubject subject, {Duration settle = const Duration(milliseconds: 300), String? shell, List< ShotAction> actions = const [], ShotCapture capture = const PreviewCapture(), Keyboard? keyboard, Map<String, String> networkImages = const {}, ShotPlatform platform = ShotPlatform.android, double pixelRatio = 2, SafeAreaInsets? safeArea, ShotBrightness brightness = ShotBrightness.light, double textScale = 1, String? locale, bool semantics = false, void onProgress(ShotProgress event)?}) → Future<ShotRun> -
Shoots
subjectin the Flutter project at or aboveprojectDirinto a new run, asshutter shot, orshutter semanticswithsemantics. Relative paths, of preview files, imports,shell, andnetworkImagesfiles, are relative toprojectDir; the current directory plays no part.
Exceptions / Errors
- ShutterException
-
An expected failure with a user-facing message and a sysexits-aligned
exit code.
runAppprints message to stderr and exits with exitCode; anything else escaping a command isEX_SOFTWARE(70).