chore: Better error handling for recording viewmodel
This commit is contained in:
parent
422e94ab45
commit
975ba31b4d
1 changed files with 13 additions and 6 deletions
|
|
@ -33,7 +33,6 @@ class RecordingViewModelState extends State<RecordingViewModel> {
|
||||||
Timer? _recorderSubscription;
|
Timer? _recorderSubscription;
|
||||||
Duration duration = Duration.zero;
|
Duration duration = Duration.zero;
|
||||||
|
|
||||||
bool error = false;
|
|
||||||
bool isSending = false;
|
bool isSending = false;
|
||||||
|
|
||||||
bool get isRecording => _audioRecorder != null;
|
bool get isRecording => _audioRecorder != null;
|
||||||
|
|
@ -83,7 +82,11 @@ class RecordingViewModelState extends State<RecordingViewModel> {
|
||||||
|
|
||||||
final result = await audioRecorder.hasPermission();
|
final result = await audioRecorder.hasPermission();
|
||||||
if (result != true) {
|
if (result != true) {
|
||||||
setState(() => error = true);
|
showOkAlertDialog(
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).oopsSomethingWentWrong,
|
||||||
|
message: L10n.of(context).noPermission,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await WakelockPlus.enable();
|
await WakelockPlus.enable();
|
||||||
|
|
@ -102,9 +105,14 @@ class RecordingViewModelState extends State<RecordingViewModel> {
|
||||||
);
|
);
|
||||||
setState(() => duration = Duration.zero);
|
setState(() => duration = Duration.zero);
|
||||||
_subscribe();
|
_subscribe();
|
||||||
} catch (_) {
|
} catch (e, s) {
|
||||||
setState(() => error = true);
|
Logs().w('Unable to start voice message recording', e, s);
|
||||||
rethrow;
|
showOkAlertDialog(
|
||||||
|
context: context,
|
||||||
|
title: L10n.of(context).oopsSomethingWentWrong,
|
||||||
|
message: e.toString(),
|
||||||
|
);
|
||||||
|
setState(_reset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,7 +142,6 @@ class RecordingViewModelState extends State<RecordingViewModel> {
|
||||||
_audioRecorder?.stop();
|
_audioRecorder?.stop();
|
||||||
_audioRecorder = null;
|
_audioRecorder = null;
|
||||||
isSending = false;
|
isSending = false;
|
||||||
error = false;
|
|
||||||
fileName = null;
|
fileName = null;
|
||||||
duration = Duration.zero;
|
duration = Duration.zero;
|
||||||
amplitudeTimeline.clear();
|
amplitudeTimeline.clear();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue