screen_capture 1.0.3 copy "screen_capture: ^1.0.3" to clipboard
screen_capture: ^1.0.3 copied to clipboard

PlatformiOSmacOS

A Flutter plugin for screen recording on macOS and iOS, supporting system audio.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:screen_capture/screen_capture.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Screen Recorder Example',
      theme: ThemeData(useMaterial3: true),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Screen Recorder Example'),
        ),
        body: const ScreenRecorderWidget(),
      ),
    );
  }
}

class ScreenRecorderWidget extends StatefulWidget {
  const ScreenRecorderWidget({super.key});

  @override
  State<ScreenRecorderWidget> createState() => _ScreenRecorderWidgetState();
}

class _ScreenRecorderWidgetState extends State<ScreenRecorderWidget> {
  String _status = "Ready to Record";
  bool _isRecording = false;
  String? _lastRecordingPath;

  Future<void> _startRecording() async {
    try {
      final result = await FlutterScreenCapture.startRecording();
      setState(() {
        _status = result;
        _isRecording = true;
        _lastRecordingPath = null;
      });
    } catch (e) {
      setState(() {
        _status = "Error: $e";
      });
    }
  }

  Future<void> _stopRecording() async {
    setState(() => _status = "Stopping...");
    try {
      final filePath = await FlutterScreenCapture.stopRecording();
      setState(() {
        _isRecording = false;
        if (filePath == "Recording discarded.") {
          _status = filePath;
          _lastRecordingPath = null;
        } else {
          _status = "Recording saved!";
          _lastRecordingPath = filePath;
        }
      });
    } catch (e) {
      setState(() {
        _status = "Error: $e";
        _isRecording = false;
      });
    }
  }

  void _openInFinder() {
    if (_lastRecordingPath == null) return;
    if (Platform.isMacOS) {
      Process.run('open', ['-R', _lastRecordingPath!]);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Padding(
        padding: const EdgeInsets.all(24.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Icon(
              _isRecording ? Icons.fiber_manual_record : Icons.videocam,
              color: _isRecording ? Colors.red : Colors.grey,
              size: 48,
            ),
            const SizedBox(height: 16),
            Text(
              _status,
              style: Theme.of(context).textTheme.titleMedium,
              textAlign: TextAlign.center,
            ),
            if (_lastRecordingPath != null) ...[
              const SizedBox(height: 8),
              SelectableText(
                _lastRecordingPath!,
                style: Theme.of(context).textTheme.bodySmall,
                textAlign: TextAlign.center,
              ),
              if (Platform.isMacOS) ...[
                const SizedBox(height: 8),
                TextButton.icon(
                  onPressed: _openInFinder,
                  icon: const Icon(Icons.folder_open, size: 18),
                  label: const Text("Show in Finder"),
                ),
              ],
            ],
            const SizedBox(height: 24),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton(
                  onPressed: _isRecording ? null : _startRecording,
                  child: const Text("Start Recording"),
                ),
                const SizedBox(width: 20),
                ElevatedButton(
                  onPressed: _isRecording ? _stopRecording : null,
                  child: const Text("Stop Recording"),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
4
likes
160
points
123
downloads

Documentation

API reference

Publisher

verified publisherappquirk.com

Weekly Downloads

A Flutter plugin for screen recording on macOS and iOS, supporting system audio.

Repository (GitHub)
View/report issues

Topics

#screen-recording #screen-capture #macos #ios

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on screen_capture

Packages that implement screen_capture