Skip to content

[flutter_tools] Add flutter capture command with image/video subcommands - #190953

Open
GhagSagar23 wants to merge 4 commits into
flutter:masterfrom
Kryonex-Labs:190587-flutter-capture-command
Open

[flutter_tools] Add flutter capture command with image/video subcommands#190953
GhagSagar23 wants to merge 4 commits into
flutter:masterfrom
Kryonex-Labs:190587-flutter-capture-command

Conversation

@GhagSagar23

Copy link
Copy Markdown

Summary

Implements flutter capture image and flutter capture video as the new unified interface for device screenshots and screen recording (#190587).

  • flutter capture image — wraps per-device screenshot logic (replaces flutter screenshot)
  • flutter capture video — wraps platform-native screen recording with --duration/-d and --out/-o flags
  • flutter screenshot — marked deprecated, points users to flutter capture image

Platform support

Platform Screenshot Video Notes
Android Existing adb screenrecord Capped at 180s (platform limit)
iOS Simulator Existing simctl recordVideo SIGINT-based stop, waits for "Recording started"
iOS Device devicectl devicectl Requires Xcode 27+
macOS screencapture -x screencapture -v -V flag for duration

Key design decisions

  • Video recording uses --duration flag OR Ctrl-C to stop
  • Android: try/finally ensures adb pull runs even on Ctrl-C
  • iOS simulator: waits for stderr "Recording started" signal before starting duration timer
  • iOS device: gated on Xcode 27+ (same as existing screenshot support)
  • Skia screenshot type dropped (no video equivalent)

Test plan

  • Unit tests: 8 tests in capture_command_test.dart (no device, unsupported device, success, duration, invalid duration)
  • Manual: iOS simulator video recording produces valid MP4
  • Manual: flutter screenshot still works with deprecation notice
  • Manual: Android emulator video recording (emulator booted, pending test)
  • Manual: macOS screenshot and video (requires Screen Recording permission)
  • Manual: iOS physical device (requires Xcode 27+, not yet available)

Fixes #190587

…mands (flutter#190587)

Adds `flutter capture image` and `flutter capture video` for
device screenshot and screen recording. Deprecates `flutter screenshot`.

Supported platforms:
- Android (adb screenrecord, capped at 180s)
- iOS simulator (simctl recordVideo with SIGINT-based stop)
- iOS device (devicectl, requires Xcode 27+)
- macOS (screencapture)
@GhagSagar23
GhagSagar23 requested review from a team as code owners August 11, 2026 20:21
@GhagSagar23
GhagSagar23 requested review from reidbaker and removed request for a team August 11, 2026 20:21
@github-actions github-actions Bot added platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels. platform-macos Building on or for macOS specifically a: desktop Running on desktop team-android Owned by Android platform team team-ios Owned by iOS platform team team-macos Owned by the macOS platform team labels Aug 11, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new capture command to the Flutter tool, enabling users to take screenshots (flutter capture image) and record screens (flutter capture video) across Android, iOS, iOS Simulators, and macOS devices, while deprecating the old screenshot command. Feedback on the changes highlights critical issues, including incorrect usage of ProcessSignal.kill (which should be process.kill), potential error masking during Android recording failures, and the need to gracefully handle Ctrl-C signals to ensure recording cleanup and file retrieval can complete. Additionally, suggestions were made to simplify redundant file existence checks and capture stderr on macOS recording failures to improve diagnostics.

Comment thread packages/flutter_tools/lib/src/ios/devices.dart
Comment thread packages/flutter_tools/lib/src/ios/simulators.dart
Comment thread packages/flutter_tools/lib/src/android/android_device.dart
Comment thread packages/flutter_tools/lib/src/commands/capture.dart
Comment thread packages/flutter_tools/lib/src/commands/capture.dart
Comment thread packages/flutter_tools/lib/src/commands/capture.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/capture.dart Outdated
Comment thread packages/flutter_tools/lib/src/macos/macos_device.dart
GhagSagar23 and others added 2 commits August 12, 2026 02:00
…g, stderr capture

- Subscribe to ProcessSignal.sigint.watch() to prevent Dart VM
  immediate exit on Ctrl-C during no-duration recording
- Android: nested try/finally to avoid masking screenrecord failure
  when adb pull fails on non-existent remote file
- macOS: capture stderr on screencapture failure for diagnostics
- Simplify redundant fs.file(outputFile.path) to outputFile directly

@override
String get description => 'Take a screenshot from a connected device.';
String get description =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!
From the conversation at #190587 (comment) I think instead of deprecating flutter screenshot, rename it to flutter capture with a List<String> get aliases => const <String>['screenshot'], and have it behave the same way as flutter screenshot so there's no behavior difference to the end user. Then you can also add a flutter capture screenshot that does nothing additional. And flutter capture recording (or similar) that does the screen recording logic.

const String _kOut = 'out';

class CaptureImageCommand extends FlutterCommand {
CaptureImageCommand({required this.fs}) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the --type and --vm-service-url options.

await process.exitCode;
return;
} on Exception catch (error) {
final errorMessage = error.toString();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could DRY out the boilerplate around devicectl issues to share the logic with takeScreenshot.

@jmagman jmagman added the CICD Run CI/CD label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop CICD Run CI/CD platform-ios iOS applications specifically platform-macos Building on or for macOS specifically team-android Owned by Android platform team team-ios Owned by iOS platform team team-macos Owned by the macOS platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New flutter screenrecord command

2 participants