screen_record_flutter 0.0.1+3 copy "screen_record_flutter: ^0.0.1+3" to clipboard
screen_record_flutter: ^0.0.1+3 copied to clipboard

Flutter plugin to record the screen for user analytics.

example/lib/main.dart

import 'dart:async';
import 'dart:developer';
import 'dart:io';

import 'package:screen_record_flutter/screen_record_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_fgbg/flutter_fgbg.dart';
import 'package:path_provider/path_provider.dart';

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late StreamSubscription<FGBGType> subscription;
  final _recorder = ScreenRecord.instance;
  String pathData = "";
  String meta = "";

  @override
  void initState() {
    startRecording();
    subscription = FGBGEvents.stream.listen((event) {
      if (event == FGBGType.background) {
        stopRecording();
      } else if (event == FGBGType.foreground) {
        startRecording();
      }

      log(event.toString());
    });
    super.initState();
  }

  @override
  void dispose() {
    subscription.cancel();
    super.dispose();
  }

  void startRecording() async {
    final dir = '${(await _getSavedDir())}';
    await Directory(dir).create(recursive: true);
    final stem =
        '$dir/${DateTime.now().toIso8601String().replaceAll(".", "").replaceAll(":", "")}';
    pathData = '$stem.mp4';
    meta = '$stem.meta';

    log('RECORDED VIDEO PATH = $pathData');

    await _recorder
        .start(
      pathVideo: pathData,
      pathMetadata: meta,
    )
        .then((value) {
      log("RECORDING STARTED");
    });
  }

  void stopRecording() {
    _recorder.stop().then((value) {
      log("RECORDING STOPPED");
    });
  }

  static Future<String?> _getSavedDir() async {
    String? externalStorageDirPath;

    if (Platform.isAndroid) {
      try {
        externalStorageDirPath = '/storage/emulated/0/Download';
      } catch (e) {
        final directory = await getExternalStorageDirectory();
        externalStorageDirPath = directory?.path;
      }
    } else if (Platform.isIOS) {
      externalStorageDirPath =
          (await getApplicationDocumentsDirectory()).absolute.path;
    }
    log('PATH FOR DOWNLOAD ::: $externalStorageDirPath');
    return externalStorageDirPath;
  }

  

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: ListView.builder(
          itemBuilder: (context, index) => ListTile(
            onTap: () {
              Navigator.of(context)
                  .push(MaterialPageRoute(builder: (_) => const SecondPage()));
            },
            title: Text('Item $index'),
            subtitle: Text('Random text $index'),
          ),
        ),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return const Scaffold(
      body: SafeArea(
        child: Column(
          children: [Text("data")],
        ),
      ),
    );
  }
}
3
likes
120
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin to record the screen for user analytics.

Documentation

API reference

License

MIT (license)

Dependencies

chewie, clock, collection, file, fixnum, flutter, path, path_provider, plugin_platform_interface, protobuf, synchronized, video_player

More

Packages that depend on screen_record_flutter

Packages that implement screen_record_flutter