Fix: Resolve critical linting issues and bugs (concurrency, syntax, dead code)

This commit is contained in:
2026-02-10 19:12:01 +05:30
parent 5e7bf0d5c0
commit 7570ffa3b9
46 changed files with 4057 additions and 1299 deletions

View File

@@ -128,9 +128,7 @@ class ClientCreateOrderRepositoryImpl
final double rate = order.roleRates[position.role] ?? 0;
final double totalValue = rate * hours * position.count;
print(
'CreateOneTimeOrder shiftRole: start=${start.toIso8601String()} end=${normalizedEnd.toIso8601String()}',
);
await executeProtected(() => _dataConnect
.createShiftRole(

View File

@@ -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/usecases/get_order_types_usecase.dart';
import 'client_create_order_event.dart';
@@ -6,7 +7,8 @@ import 'client_create_order_state.dart';
/// BLoC for managing the list of available order types.
class ClientCreateOrderBloc
extends Bloc<ClientCreateOrderEvent, ClientCreateOrderState> {
extends Bloc<ClientCreateOrderEvent, ClientCreateOrderState>
with BlocErrorHandler<ClientCreateOrderState> {
ClientCreateOrderBloc(this._getOrderTypesUseCase)
: super(const ClientCreateOrderInitial()) {
on<ClientCreateOrderTypesRequested>(_onTypesRequested);
@@ -17,7 +19,14 @@ class ClientCreateOrderBloc
ClientCreateOrderTypesRequested event,
Emitter<ClientCreateOrderState> emit,
) async {
final List<OrderType> types = await _getOrderTypesUseCase();
emit(ClientCreateOrderLoadSuccess(types));
await handleError(
emit: emit,
action: () async {
final List<OrderType> types = await _getOrderTypesUseCase();
emit(ClientCreateOrderLoadSuccess(types));
},
onError: (String errorKey) => ClientCreateOrderLoadFailure(errorKey),
);
}
}

View File

@@ -24,3 +24,13 @@ class ClientCreateOrderLoadSuccess extends ClientCreateOrderState {
@override
List<Object?> get props => <Object?>[orderTypes];
}
/// State representing a failure to load order types.
class ClientCreateOrderLoadFailure extends ClientCreateOrderState {
const ClientCreateOrderLoadFailure(this.error);
final String error;
@override
List<Object?> get props => <Object?>[error];
}

View File

@@ -1,5 +1,6 @@
import 'package:firebase_data_connect/firebase_data_connect.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:krow_core/core.dart';
import 'package:krow_data_connect/krow_data_connect.dart' as dc;
import 'package:krow_domain/krow_domain.dart';
import '../../domain/arguments/one_time_order_arguments.dart';
@@ -8,7 +9,8 @@ import 'one_time_order_event.dart';
import 'one_time_order_state.dart';
/// BLoC for managing the multi-step one-time order creation form.
class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState> {
class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
with BlocErrorHandler<OneTimeOrderState> {
OneTimeOrderBloc(this._createOneTimeOrderUseCase, this._dataConnect)
: super(OneTimeOrderState.initial()) {
on<OneTimeOrderVendorsLoaded>(_onVendorsLoaded);
@@ -29,79 +31,93 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState> {
final dc.ExampleConnector _dataConnect;
Future<void> _loadVendors() async {
try {
final QueryResult<dc.ListVendorsData, void> result = await _dataConnect.listVendors().execute();
final List<Vendor> vendors = result.data.vendors
.map(
(dc.ListVendorsVendors vendor) => Vendor(
id: vendor.id,
name: vendor.companyName,
rates: const <String, double>{},
),
)
.toList();
final List<Vendor>? vendors = await handleErrorWithResult(
action: () async {
final QueryResult<dc.ListVendorsData, void> result =
await _dataConnect.listVendors().execute();
return result.data.vendors
.map(
(dc.ListVendorsVendors vendor) => Vendor(
id: vendor.id,
name: vendor.companyName,
rates: const <String, double>{},
),
)
.toList();
},
onError: (_) => add(const OneTimeOrderVendorsLoaded(<Vendor>[])),
);
if (vendors != null) {
add(OneTimeOrderVendorsLoaded(vendors));
} catch (_) {
add(const OneTimeOrderVendorsLoaded(<Vendor>[]));
}
}
Future<void> _loadRolesForVendor(String vendorId) async {
try {
final QueryResult<dc.ListRolesByVendorIdData, dc.ListRolesByVendorIdVariables> result = await _dataConnect.listRolesByVendorId(
vendorId: vendorId,
).execute();
final List<OneTimeOrderRoleOption> roles = result.data.roles
.map(
(dc.ListRolesByVendorIdRoles role) => OneTimeOrderRoleOption(
id: role.id,
name: role.name,
costPerHour: role.costPerHour,
),
)
.toList();
Future<void> _loadRolesForVendor(String vendorId, Emitter<OneTimeOrderState> emit) async {
final List<OneTimeOrderRoleOption>? roles = await handleErrorWithResult(
action: () async {
final QueryResult<dc.ListRolesByVendorIdData, dc.ListRolesByVendorIdVariables>
result = await _dataConnect.listRolesByVendorId(vendorId: vendorId).execute();
return result.data.roles
.map(
(dc.ListRolesByVendorIdRoles role) => OneTimeOrderRoleOption(
id: role.id,
name: role.name,
costPerHour: role.costPerHour,
),
)
.toList();
},
onError: (_) => emit(state.copyWith(roles: const <OneTimeOrderRoleOption>[])),
);
if (roles != null) {
emit(state.copyWith(roles: roles));
} catch (_) {
emit(state.copyWith(roles: const <OneTimeOrderRoleOption>[]));
}
}
Future<void> _loadHubs() async {
try {
final String? businessId = dc.ClientSessionStore.instance.session?.business?.id;
if (businessId == null || businessId.isEmpty) {
add(const OneTimeOrderHubsLoaded(<OneTimeOrderHubOption>[]));
return;
}
final QueryResult<dc.ListTeamHubsByOwnerIdData, dc.ListTeamHubsByOwnerIdVariables>
result = await _dataConnect.listTeamHubsByOwnerId(ownerId: businessId).execute();
final List<OneTimeOrderHubOption> hubs = result.data.teamHubs
.map(
(dc.ListTeamHubsByOwnerIdTeamHubs hub) => OneTimeOrderHubOption(
id: hub.id,
name: hub.hubName,
address: hub.address,
placeId: hub.placeId,
latitude: hub.latitude,
longitude: hub.longitude,
city: hub.city,
state: hub.state,
street: hub.street,
country: hub.country,
zipCode: hub.zipCode,
),
)
.toList();
final List<OneTimeOrderHubOption>? hubs = await handleErrorWithResult(
action: () async {
final String? businessId =
dc.ClientSessionStore.instance.session?.business?.id;
if (businessId == null || businessId.isEmpty) {
return <OneTimeOrderHubOption>[];
}
final QueryResult<dc.ListTeamHubsByOwnerIdData, dc.ListTeamHubsByOwnerIdVariables>
result = await _dataConnect
.listTeamHubsByOwnerId(ownerId: businessId)
.execute();
return result.data.teamHubs
.map(
(dc.ListTeamHubsByOwnerIdTeamHubs hub) => OneTimeOrderHubOption(
id: hub.id,
name: hub.hubName,
address: hub.address,
placeId: hub.placeId,
latitude: hub.latitude,
longitude: hub.longitude,
city: hub.city,
state: hub.state,
street: hub.street,
country: hub.country,
zipCode: hub.zipCode,
),
)
.toList();
},
onError: (_) => add(const OneTimeOrderHubsLoaded(<OneTimeOrderHubOption>[])),
);
if (hubs != null) {
add(OneTimeOrderHubsLoaded(hubs));
} catch (_) {
add(const OneTimeOrderHubsLoaded(<OneTimeOrderHubOption>[]));
}
}
void _onVendorsLoaded(
Future<void> _onVendorsLoaded(
OneTimeOrderVendorsLoaded event,
Emitter<OneTimeOrderState> emit,
) {
) async {
final Vendor? selectedVendor =
event.vendors.isNotEmpty ? event.vendors.first : null;
emit(
@@ -111,16 +127,16 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState> {
),
);
if (selectedVendor != null) {
_loadRolesForVendor(selectedVendor.id);
await _loadRolesForVendor(selectedVendor.id, emit);
}
}
void _onVendorChanged(
Future<void> _onVendorChanged(
OneTimeOrderVendorChanged event,
Emitter<OneTimeOrderState> emit,
) {
) async {
emit(state.copyWith(selectedVendor: event.vendor));
_loadRolesForVendor(event.vendor.id);
await _loadRolesForVendor(event.vendor.id, emit);
}
void _onHubsLoaded(
@@ -207,44 +223,45 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState> {
Emitter<OneTimeOrderState> emit,
) async {
emit(state.copyWith(status: OneTimeOrderStatus.loading));
try {
final Map<String, double> roleRates = <String, double>{
for (final OneTimeOrderRoleOption role in state.roles) role.id: role.costPerHour,
};
final OneTimeOrderHubOption? selectedHub = state.selectedHub;
if (selectedHub == null) {
throw Exception('Hub is missing.');
}
final OneTimeOrder order = OneTimeOrder(
date: state.date,
location: selectedHub.name,
positions: state.positions,
hub: OneTimeOrderHubDetails(
id: selectedHub.id,
name: selectedHub.name,
address: selectedHub.address,
placeId: selectedHub.placeId,
latitude: selectedHub.latitude,
longitude: selectedHub.longitude,
city: selectedHub.city,
state: selectedHub.state,
street: selectedHub.street,
country: selectedHub.country,
zipCode: selectedHub.zipCode,
),
eventName: state.eventName,
vendorId: state.selectedVendor?.id,
roleRates: roleRates,
);
await _createOneTimeOrderUseCase(OneTimeOrderArguments(order: order));
emit(state.copyWith(status: OneTimeOrderStatus.success));
} catch (e) {
emit(
state.copyWith(
status: OneTimeOrderStatus.failure,
errorMessage: e.toString(),
),
);
}
await handleError(
emit: emit,
action: () async {
final Map<String, double> roleRates = <String, double>{
for (final OneTimeOrderRoleOption role in state.roles)
role.id: role.costPerHour,
};
final OneTimeOrderHubOption? selectedHub = state.selectedHub;
if (selectedHub == null) {
throw const OrderMissingHubException();
}
final OneTimeOrder order = OneTimeOrder(
date: state.date,
location: selectedHub.name,
positions: state.positions,
hub: OneTimeOrderHubDetails(
id: selectedHub.id,
name: selectedHub.name,
address: selectedHub.address,
placeId: selectedHub.placeId,
latitude: selectedHub.latitude,
longitude: selectedHub.longitude,
city: selectedHub.city,
state: selectedHub.state,
street: selectedHub.street,
country: selectedHub.country,
zipCode: selectedHub.zipCode,
),
eventName: state.eventName,
vendorId: state.selectedVendor?.id,
roleRates: roleRates,
);
await _createOneTimeOrderUseCase(OneTimeOrderArguments(order: order));
emit(state.copyWith(status: OneTimeOrderStatus.success));
},
onError: (String errorKey) => state.copyWith(
status: OneTimeOrderStatus.failure,
errorMessage: errorKey,
),
);
}
}

View File

@@ -1,11 +1,13 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:krow_core/core.dart';
import '../../domain/arguments/rapid_order_arguments.dart';
import '../../domain/usecases/create_rapid_order_usecase.dart';
import 'rapid_order_event.dart';
import 'rapid_order_state.dart';
/// BLoC for managing the rapid (urgent) order creation flow.
class RapidOrderBloc extends Bloc<RapidOrderEvent, RapidOrderState> {
class RapidOrderBloc extends Bloc<RapidOrderEvent, RapidOrderState>
with BlocErrorHandler<RapidOrderState> {
RapidOrderBloc(this._createRapidOrderUseCase)
: super(
const RapidOrderInitial(
@@ -64,19 +66,18 @@ class RapidOrderBloc extends Bloc<RapidOrderEvent, RapidOrderState> {
final RapidOrderState currentState = state;
if (currentState is RapidOrderInitial) {
final String message = currentState.message;
print('RapidOrder submit: message="$message"');
emit(const RapidOrderSubmitting());
try {
await _createRapidOrderUseCase(
RapidOrderArguments(description: message),
);
print('RapidOrder submit: success');
emit(const RapidOrderSuccess());
} catch (e) {
print('RapidOrder submit: error=$e');
emit(RapidOrderFailure(e.toString()));
}
await handleError(
emit: emit,
action: () async {
await _createRapidOrderUseCase(
RapidOrderArguments(description: message),
);
emit(const RapidOrderSuccess());
},
onError: (String errorKey) => RapidOrderFailure(errorKey),
);
}
}
@@ -90,3 +91,4 @@ class RapidOrderBloc extends Bloc<RapidOrderEvent, RapidOrderState> {
}
}
}