Fix: Resolve critical linting issues and bugs (concurrency, syntax, dead code)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:krow_core/core.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import '../../../domain/arguments/get_payment_history_arguments.dart';
|
||||
import '../../../domain/usecases/get_payment_history_usecase.dart';
|
||||
@@ -6,8 +7,8 @@ import '../../../domain/usecases/get_payment_summary_usecase.dart';
|
||||
import 'payments_event.dart';
|
||||
import 'payments_state.dart';
|
||||
|
||||
class PaymentsBloc extends Bloc<PaymentsEvent, PaymentsState> {
|
||||
|
||||
class PaymentsBloc extends Bloc<PaymentsEvent, PaymentsState>
|
||||
with BlocErrorHandler<PaymentsState> {
|
||||
PaymentsBloc({
|
||||
required this.getPaymentSummary,
|
||||
required this.getPaymentHistory,
|
||||
@@ -23,20 +24,24 @@ class PaymentsBloc extends Bloc<PaymentsEvent, PaymentsState> {
|
||||
Emitter<PaymentsState> emit,
|
||||
) async {
|
||||
emit(PaymentsLoading());
|
||||
try {
|
||||
final PaymentSummary currentSummary = await getPaymentSummary();
|
||||
|
||||
final List<StaffPayment> history = await getPaymentHistory(
|
||||
const GetPaymentHistoryArguments('week'),
|
||||
);
|
||||
emit(PaymentsLoaded(
|
||||
summary: currentSummary,
|
||||
history: history,
|
||||
activePeriod: 'week',
|
||||
));
|
||||
} catch (e) {
|
||||
emit(PaymentsError(e.toString()));
|
||||
}
|
||||
await handleError(
|
||||
emit: emit,
|
||||
action: () async {
|
||||
final PaymentSummary currentSummary = await getPaymentSummary();
|
||||
|
||||
final List<StaffPayment> history = await getPaymentHistory(
|
||||
const GetPaymentHistoryArguments('week'),
|
||||
);
|
||||
emit(
|
||||
PaymentsLoaded(
|
||||
summary: currentSummary,
|
||||
history: history,
|
||||
activePeriod: 'week',
|
||||
),
|
||||
);
|
||||
},
|
||||
onError: (String errorKey) => PaymentsError(errorKey),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onChangePeriod(
|
||||
@@ -45,17 +50,22 @@ class PaymentsBloc extends Bloc<PaymentsEvent, PaymentsState> {
|
||||
) async {
|
||||
final PaymentsState currentState = state;
|
||||
if (currentState is PaymentsLoaded) {
|
||||
try {
|
||||
final List<StaffPayment> newHistory = await getPaymentHistory(
|
||||
GetPaymentHistoryArguments(event.period),
|
||||
);
|
||||
emit(currentState.copyWith(
|
||||
history: newHistory,
|
||||
activePeriod: event.period,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(PaymentsError(e.toString()));
|
||||
}
|
||||
await handleError(
|
||||
emit: emit,
|
||||
action: () async {
|
||||
final List<StaffPayment> newHistory = await getPaymentHistory(
|
||||
GetPaymentHistoryArguments(event.period),
|
||||
);
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
history: newHistory,
|
||||
activePeriod: event.period,
|
||||
),
|
||||
);
|
||||
},
|
||||
onError: (String errorKey) => PaymentsError(errorKey),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user