shot function

Future<ShotRun> shot(
  1. String projectDir,
  2. ShotSubject subject, {
  3. Duration settle = const Duration(milliseconds: 300),
  4. String? shell,
  5. List<ShotAction> actions = const [],
  6. ShotCapture capture = const PreviewCapture(),
  7. Keyboard? keyboard,
  8. Map<String, String> networkImages = const {},
  9. ShotPlatform platform = ShotPlatform.android,
  10. double pixelRatio = 2,
  11. SafeAreaInsets? safeArea,
  12. ShotBrightness brightness = ShotBrightness.light,
  13. double textScale = 1,
  14. String? locale,
  15. bool semantics = false,
  16. void onProgress(
    1. ShotProgress event
    )?,
})

Shoots subject in the Flutter project at or above projectDir into a new run, as shutter shot, or shutter semantics with semantics. Relative paths, of preview files, imports, shell, and networkImages files, are relative to projectDir; the current directory plays no part.

A shot that fails to render is a ShotStatus.error in the returned run. A run that cannot be shot throws a ShutterException instead, leaving the project as it was: no Flutter SDK, arguments that do not fit together, a missing file, or a project that cannot render.

  • settle: pumped once before capture, and again, in 16 ms frames, after each action.
  • shell: the shell file to use instead of <preview dir>/shell.dart.
  • actions: performed on every preview before the capture, in order; at most one press, hover, or focus, which comes last.
  • networkImages: the file served to Image.network for each URL.
  • platform: the platform the app is drawn as.
  • pixelRatio: the device pixel ratio the app is drawn at, > 0: pixels of the PNG per logical pixel.
  • safeArea: the safe area the app is laid out with; none lays it out without one.
  • brightness, textScale: the platform brightness and text scale (> 0) reported to every preview that sets none of its own.
  • locale: the locale reported as the device's, a language tag of a language, an optional script, and an optional region, e.g. ja-JP or zh-Hant-TW; none keeps flutter test's en-US.
  • onProgress: told of what the run is doing as it does it.

Implementation

Future<ShotRun> 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 Function(ShotProgress event)? onProgress,
}) => shoot(
  ShutterContext(workingDirectory: projectDir),
  subject,
  settle: settle,
  shell: shell,
  actions: actions,
  capture: capture,
  keyboard: keyboard,
  networkImages: networkImages,
  platform: platform,
  pixelRatio: pixelRatio,
  safeArea: safeArea,
  brightness: brightness,
  textScale: textScale,
  locale: locale,
  semantics: semantics,
  onProgress: onProgress,
).then(shotRun);