From c54b817ac4329f0389b84c1d5ebb624fc68d0dd9 Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Fri, 27 Feb 2026 13:25:51 -0500 Subject: [PATCH] Use handleError for audio recording actions Refactor RapidOrderBloc to wrap start/stop recording logic with handleError (adds onError handling and standardized emit closure). Rename isListening var to alreadyListening and tweak comments. Remove the overridden close() that disposed the audio recorder (disposal likely handled elsewhere). Also remove an unused import (krow_domain) from create_order_view to clean up warnings. --- .../blocs/rapid_order/rapid_order_bloc.dart | 26 +++++++++---------- .../create_order/create_order_view.dart | 1 - 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/apps/mobile/packages/features/client/orders/create_order/lib/src/presentation/blocs/rapid_order/rapid_order_bloc.dart b/apps/mobile/packages/features/client/orders/create_order/lib/src/presentation/blocs/rapid_order/rapid_order_bloc.dart index 2a12d9c3..7967b166 100644 --- a/apps/mobile/packages/features/client/orders/create_order/lib/src/presentation/blocs/rapid_order/rapid_order_bloc.dart +++ b/apps/mobile/packages/features/client/orders/create_order/lib/src/presentation/blocs/rapid_order/rapid_order_bloc.dart @@ -47,18 +47,24 @@ class RapidOrderBloc extends Bloc ) async { if (state is RapidOrderInitial) { final RapidOrderInitial currentState = state as RapidOrderInitial; - final bool newListeningState = !currentState.isListening; + final bool alreadyListening = currentState.isListening; - if (newListeningState) { - // Start Recording - await _audioRecorderService.startRecording(); - emit(currentState.copyWith(isListening: true)); + if (!alreadyListening) { + // Start recording + await handleError( + emit: (RapidOrderState s) => emit(s), + action: () async { + await _audioRecorderService.startRecording(); + emit(currentState.copyWith(isListening: true)); + }, + onError: (String errorKey) => RapidOrderFailure(errorKey), + ); } else { - // Stop Recording and Transcribe + // Stop and transcribe emit(currentState.copyWith(isListening: false)); await handleError( - emit: emit.call, + emit: (RapidOrderState s) => emit(s), action: () async { final String? path = await _audioRecorderService.stopRecording(); if (path != null) { @@ -109,10 +115,4 @@ class RapidOrderBloc extends Bloc emit((state as RapidOrderInitial).copyWith(message: cleanedExample)); } } - - @override - Future close() { - _audioRecorderService.dispose(); - return super.close(); - } } diff --git a/apps/mobile/packages/features/client/orders/create_order/lib/src/presentation/widgets/create_order/create_order_view.dart b/apps/mobile/packages/features/client/orders/create_order/lib/src/presentation/widgets/create_order/create_order_view.dart index 0c39efdd..a554bf52 100644 --- a/apps/mobile/packages/features/client/orders/create_order/lib/src/presentation/widgets/create_order/create_order_view.dart +++ b/apps/mobile/packages/features/client/orders/create_order/lib/src/presentation/widgets/create_order/create_order_view.dart @@ -3,7 +3,6 @@ import 'package:design_system/design_system.dart'; import 'package:flutter/material.dart'; import 'package:flutter_modular/flutter_modular.dart'; import 'package:krow_core/core.dart'; -import 'package:krow_domain/krow_domain.dart'; import '../../utils/constants/order_types.dart'; import '../../utils/ui_entities/order_type_ui_metadata.dart'; import '../order_type_card.dart';