From 975ba31b4d461972d067f680fc6da9c27db3422a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Tue, 28 Oct 2025 07:38:54 +0100 Subject: [PATCH] chore: Better error handling for recording viewmodel --- lib/pages/chat/recording_view_model.dart | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/pages/chat/recording_view_model.dart b/lib/pages/chat/recording_view_model.dart index 4c3471008..ae5ca637f 100644 --- a/lib/pages/chat/recording_view_model.dart +++ b/lib/pages/chat/recording_view_model.dart @@ -33,7 +33,6 @@ class RecordingViewModelState extends State { Timer? _recorderSubscription; Duration duration = Duration.zero; - bool error = false; bool isSending = false; bool get isRecording => _audioRecorder != null; @@ -83,7 +82,11 @@ class RecordingViewModelState extends State { final result = await audioRecorder.hasPermission(); if (result != true) { - setState(() => error = true); + showOkAlertDialog( + context: context, + title: L10n.of(context).oopsSomethingWentWrong, + message: L10n.of(context).noPermission, + ); return; } await WakelockPlus.enable(); @@ -102,9 +105,14 @@ class RecordingViewModelState extends State { ); setState(() => duration = Duration.zero); _subscribe(); - } catch (_) { - setState(() => error = true); - rethrow; + } catch (e, s) { + Logs().w('Unable to start voice message recording', e, s); + showOkAlertDialog( + context: context, + title: L10n.of(context).oopsSomethingWentWrong, + message: e.toString(), + ); + setState(_reset); } } @@ -134,7 +142,6 @@ class RecordingViewModelState extends State { _audioRecorder?.stop(); _audioRecorder = null; isSending = false; - error = false; fileName = null; duration = Duration.zero; amplitudeTimeline.clear();