From 4342f0a8b68c61fd07514d991977b295549158a9 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sun, 15 Mar 2020 11:49:59 +0100 Subject: [PATCH] Pop on error --- lib/components/dialogs/recording_dialog.dart | 27 ++++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/components/dialogs/recording_dialog.dart b/lib/components/dialogs/recording_dialog.dart index 5351e50..12fcf7a 100644 --- a/lib/components/dialogs/recording_dialog.dart +++ b/lib/components/dialogs/recording_dialog.dart @@ -20,15 +20,21 @@ class _RecordingDialogState extends State { StreamSubscription _recorderSubscription; + bool error = false; + void startRecording() async { - await flutterSound.startRecorder( - codec: t_CODEC.CODEC_AAC, - ); - _recorderSubscription = flutterSound.onRecorderStateChanged.listen((e) { - DateTime date = - DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt()); - setState(() => time = DateFormat('mm:ss:SS', 'en_US').format(date)); - }); + try { + await flutterSound.startRecorder( + codec: t_CODEC.CODEC_AAC, + ); + _recorderSubscription = flutterSound.onRecorderStateChanged.listen((e) { + DateTime date = + DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt()); + setState(() => time = DateFormat('mm:ss:SS', 'en_US').format(date)); + }); + } catch (e) { + error = true; + } } @override @@ -46,6 +52,11 @@ class _RecordingDialogState extends State { @override Widget build(BuildContext context) { + if (error) { + Timer(Duration(seconds: 1), () { + Navigator.of(context).pop(); + }); + } return AlertDialog( content: Row( children: [