fix: Keep display alive while recording

This commit is contained in:
Christian Pauly 2021-08-11 21:17:11 +02:00
parent b3e3419508
commit ddba6c2ad6
3 changed files with 5 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:record/record.dart'; import 'package:record/record.dart';
import 'package:wakelock/wakelock.dart';
class RecordingDialog extends StatefulWidget { class RecordingDialog extends StatefulWidget {
static const String recordingFileType = 'aac'; static const String recordingFileType = 'aac';
@ -35,6 +36,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
setState(() => error = true); setState(() => error = true);
return; return;
} }
await Wakelock.enable();
await _audioRecorder.start( await _audioRecorder.start(
path: _recordedPath, encoder: AudioEncoder.AAC); path: _recordedPath, encoder: AudioEncoder.AAC);
setState(() => _duration = Duration.zero); setState(() => _duration = Duration.zero);
@ -55,6 +57,7 @@ class _RecordingDialogState extends State<RecordingDialog> {
@override @override
void dispose() { void dispose() {
Wakelock.disable();
_recorderSubscription?.cancel(); _recorderSubscription?.cancel();
_audioRecorder.stop(); _audioRecorder.stop();
super.dispose(); super.dispose();

View File

@ -1501,7 +1501,7 @@ packages:
source: hosted source: hosted
version: "1.2.0+11" version: "1.2.0+11"
wakelock: wakelock:
dependency: transitive dependency: "direct main"
description: description:
name: wakelock name: wakelock
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"

View File

@ -68,6 +68,7 @@ dependencies:
universal_html: ^2.0.8 universal_html: ^2.0.8
url_launcher: ^6.0.9 url_launcher: ^6.0.9
vrouter: 1.2.0+11 vrouter: 1.2.0+11
wakelock: ^0.5.3+3
dev_dependencies: dev_dependencies:
dapackages: ^1.6.0 dapackages: ^1.6.0