screen_recoder_7 1.10.2 copy "screen_recoder_7: ^1.10.2" to clipboard
screen_recoder_7: ^1.10.2 copied to clipboard

screen recoder for android and ios.

example/lib/main.dart

import 'dart:async';
import 'dart:developer';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:screen_recoder_7/screen_recoder_7.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark(),
      debugShowCheckedModeBanner: false,
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  Screenrecoder7? screenRecorder;
  Map<String, dynamic>? _response;
  bool inProgress = false;

  @override
  void initState() {
    super.initState();
    screenRecorder = Screenrecoder7();
  }

  Future<void> startRecord({required String fileName}) async {
//     if you need to add your name directory then you have to add this code
//      remove dirPathToSave parameter and add directory.
// try {
//       var startResponse = await screenRecorder?.startRecordScreen(
//         directory: "screen_recorder_7",
//         fileName: "testrecording",
//         audioEnable: false,
//       );
//       setState(() {
//         _response = startResponse;
//       });
//       try {
//         screenRecorder?.watcher?.events.listen(
//           (event) {
//             log(event.type.toString(), name: "Event: ");
//           },
//           onError: (e) => kDebugMode ? debugPrint('ERROR ON STREAM: $e') : null,
//           onDone: () => kDebugMode ? debugPrint('Watcher closed!') : null,
//         );
//       } catch (e) {
//         kDebugMode ? debugPrint('ERROR WAITING FOR READY: $e') : null;
//       }
//     } on PlatformException {
//       kDebugMode
//           ? debugPrint("Error: An error occurred while starting the recording!")
//           : null;
//     }
    //Directory? tempDir = await getApplicationDocumentsDirectory();
    //String? tempPath = tempDir.path;
    try {
      var startResponse = await screenRecorder?.startRecordScreen(
          directory: "screen_recorder_7",
          fileName: "testrecording",
          //dirPathToSave: tempPath, //Optional. It will save the video there when you give the file path with whatever you want.
          audioEnable: true,
          wasHDSelected: true);
      setState(() {
        _response = startResponse;
      });
      try {
        screenRecorder?.watcher?.events.listen(
          (event) {
            log(event.type.toString(), name: "Event: ");
          },
          onError: (e) => kDebugMode ? debugPrint('ERROR ON STREAM: $e') : null,
          onDone: () => kDebugMode ? debugPrint('Watcher closed!') : null,
        );
      } catch (e) {
        kDebugMode ? debugPrint('ERROR WAITING FOR READY: $e') : null;
      }
    } on PlatformException {
      kDebugMode
          ? debugPrint("Error: An error occurred while starting the recording!")
          : null;
    }
  }

  Future<void> stopRecord() async {
    try {
      var stopResponse = await screenRecorder?.stopRecord();
      setState(() {
        _response = stopResponse;
      });
    } on PlatformException {
      kDebugMode
          ? debugPrint("Error: An error occurred while stopping recording.")
          : null;
    }
  }

  Future<void> pauseRecord() async {
    try {
      await screenRecorder?.pauseRecord();
    } on PlatformException {
      kDebugMode
          ? debugPrint("Error: An error occurred while pause recording.")
          : null;
    }
  }

  Future<void> resumeRecord() async {
    try {
      await screenRecorder?.resumeRecord();
    } on PlatformException {
      kDebugMode
          ? debugPrint("Error: An error occurred while resume recording.")
          : null;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Screen Recording Debug"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text("File: ${(_response?['file'] as File?)}"),
            Text("filedirectory: ${(_response?['filedirectory'] as File?)}"),
            Text("fileName: ${_response?['fileName']}"),
            Text("Filesize: ${(_response?['filesize'].toString())}"),
            Text("addfilesize: ${(_response?['addfilesize'].toString())}"),
            Text("Status: ${(_response?['success']).toString()}"),
            Text("cloudStorage: ${(_response?['cloudStorage']).toString()}"),
            Text("Event: ${_response?['eventname']}"),
            Text("Progress: ${(_response?['progressing']).toString()}"),
            Text("Message: ${_response?['message']}"),
            Text("Video Hash: ${_response?['videohash']}"),
            Text("Start Date: ${(_response?['startdate']).toString()}"),
            Text("End Date: ${(_response?['enddate']).toString()}"),
            ElevatedButton(
                onPressed: () => startRecord(fileName: "testrecording"),
                child: const Text('START RECORD')),
            ElevatedButton(
                onPressed: () => resumeRecord(),
                child: const Text('RESUME RECORD')),
            ElevatedButton(
                onPressed: () => pauseRecord(),
                child: const Text('PAUSE RECORD')),
            ElevatedButton(
                onPressed: () => stopRecord(),
                child: const Text('STOP RECORD')),
          ],
        ),
      ),
    );
  }
}