ed_screen_recorder 0.0.10 ed_screen_recorder: ^0.0.10 copied to clipboard
Screen Recorder for Flutter. This plug-in requires Android SDK 21+ and iOS 10+
import 'dart:async';
import 'dart:developer';
import 'dart:io';
import 'package:ed_screen_recorder/ed_screen_recorder.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.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> {
EdScreenRecorder? screenRecorder;
Map<String, dynamic>? _response;
bool inProgress = false;
@override
void initState() {
super.initState();
screenRecorder = EdScreenRecorder();
}
Future<void> startRecord({required String fileName}) async {
// Directory tempDir = await getTemporaryDirectory();
// String tempPath = tempDir.path;
try {
var startResponse = await screenRecorder?.startRecordScreen(
fileName: "Eren",
//dirPathToSave: tempPath, //Optional. It will save the video there when you give the file path with whatever you want.
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;
}
}
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;
}
}
@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?)?.path}"),
Text("Status: ${(_response?['success']).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: "eren"),
child: const Text('START RECORD')),
ElevatedButton(
onPressed: () => stopRecord(),
child: const Text('STOP RECORD')),
],
),
),
);
}
}