Fix: Resolve critical linting issues and bugs (concurrency, syntax, dead code)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:client_home/src/domain/repositories/home_repository_interface.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:krow_core/core.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import '../../domain/usecases/get_dashboard_data_usecase.dart';
|
||||
import '../../domain/usecases/get_recent_reorders_usecase.dart';
|
||||
@@ -8,8 +9,8 @@ import 'client_home_event.dart';
|
||||
import 'client_home_state.dart';
|
||||
|
||||
/// BLoC responsible for managing the state and business logic of the client home dashboard.
|
||||
class ClientHomeBloc extends Bloc<ClientHomeEvent, ClientHomeState> {
|
||||
|
||||
class ClientHomeBloc extends Bloc<ClientHomeEvent, ClientHomeState>
|
||||
with BlocErrorHandler<ClientHomeState> {
|
||||
ClientHomeBloc({
|
||||
required GetDashboardDataUseCase getDashboardDataUseCase,
|
||||
required GetRecentReordersUseCase getRecentReordersUseCase,
|
||||
@@ -35,31 +36,31 @@ class ClientHomeBloc extends Bloc<ClientHomeEvent, ClientHomeState> {
|
||||
Emitter<ClientHomeState> emit,
|
||||
) async {
|
||||
emit(state.copyWith(status: ClientHomeStatus.loading));
|
||||
try {
|
||||
// Get session data
|
||||
final UserSessionData sessionData = _getUserSessionDataUseCase();
|
||||
await handleError(
|
||||
emit: emit,
|
||||
action: () async {
|
||||
// Get session data
|
||||
final UserSessionData sessionData = _getUserSessionDataUseCase();
|
||||
|
||||
// Get dashboard data
|
||||
final HomeDashboardData data = await _getDashboardDataUseCase();
|
||||
final List<ReorderItem> reorderItems = await _getRecentReordersUseCase();
|
||||
// Get dashboard data
|
||||
final HomeDashboardData data = await _getDashboardDataUseCase();
|
||||
final List<ReorderItem> reorderItems = await _getRecentReordersUseCase();
|
||||
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: ClientHomeStatus.success,
|
||||
dashboardData: data,
|
||||
reorderItems: reorderItems,
|
||||
businessName: sessionData.businessName,
|
||||
photoUrl: sessionData.photoUrl,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: ClientHomeStatus.error,
|
||||
errorMessage: e.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: ClientHomeStatus.success,
|
||||
dashboardData: data,
|
||||
reorderItems: reorderItems,
|
||||
businessName: sessionData.businessName,
|
||||
photoUrl: sessionData.photoUrl,
|
||||
),
|
||||
);
|
||||
},
|
||||
onError: (String errorKey) => state.copyWith(
|
||||
status: ClientHomeStatus.error,
|
||||
errorMessage: errorKey,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onEditModeToggled(
|
||||
@@ -73,7 +74,8 @@ class ClientHomeBloc extends Bloc<ClientHomeEvent, ClientHomeState> {
|
||||
ClientHomeWidgetVisibilityToggled event,
|
||||
Emitter<ClientHomeState> emit,
|
||||
) {
|
||||
final Map<String, bool> newVisibility = Map<String, bool>.from(state.widgetVisibility);
|
||||
final Map<String, bool> newVisibility =
|
||||
Map<String, bool>.from(state.widgetVisibility);
|
||||
newVisibility[event.widgetId] = !(newVisibility[event.widgetId] ?? true);
|
||||
emit(state.copyWith(widgetVisibility: newVisibility));
|
||||
}
|
||||
@@ -119,3 +121,4 @@ class ClientHomeBloc extends Bloc<ClientHomeEvent, ClientHomeState> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user