fix functional bugs
This commit is contained in:
@@ -76,6 +76,8 @@ class ActiveRideBloc extends Bloc<ActiveRideEvent, ActiveRideState> {
|
||||
cost: orderData?.price ?? 0.0,
|
||||
isPaused: isPaused,
|
||||
inZone: orderData?.zone,
|
||||
latitude: orderData?.latitude,
|
||||
longitude: orderData?.longitude,
|
||||
));
|
||||
|
||||
_syncTimer?.cancel();
|
||||
@@ -196,6 +198,8 @@ class ActiveRideBloc extends Bloc<ActiveRideEvent, ActiveRideState> {
|
||||
cost: orderData?.price ?? state.cost,
|
||||
isPaused: isPaused,
|
||||
inZone: orderData?.zone,
|
||||
latitude: orderData?.latitude,
|
||||
longitude: orderData?.longitude,
|
||||
));
|
||||
}
|
||||
print("CURRENT STATE $state");
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:be_happy/domain/entities/client_notification.dart';
|
||||
import 'package:be_happy/domain/entities/map_settings.dart';
|
||||
import 'package:be_happy/domain/usecase/check_user_usecase.dart';
|
||||
import 'package:be_happy/domain/usecase/get_available_zones_usecase.dart';
|
||||
import 'package:be_happy/domain/usecase/get_client_orders_usecase.dart';
|
||||
import 'package:be_happy/domain/usecase/get_map_settings_usecase.dart';
|
||||
import 'package:be_happy/domain/usecase/get_notifications_stream_usecase.dart';
|
||||
import 'package:be_happy/domain/usecase/logout_usecase.dart';
|
||||
@@ -13,6 +14,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../domain/entities/point.dart';
|
||||
import '../../domain/entities/scooter.dart';
|
||||
import '../../domain/entities/scooter_order.dart';
|
||||
import '../../domain/entities/zone.dart';
|
||||
import '../../domain/usecase/get_available_scooters_usecase.dart';
|
||||
import '../../domain/usecase/get_profile_usecase.dart';
|
||||
@@ -23,6 +25,7 @@ import 'package:maps_toolkit/maps_toolkit.dart' as mt;
|
||||
|
||||
class MapBloc extends Bloc<ScooterEvent, ScooterState> {
|
||||
final GetAvailableScootersUsecase getScootersUsecase;
|
||||
final GetClientOrdersUsecase getClientOrdersUsecase;
|
||||
final GetAvailableZonesUsecase getAvailableZonesUsecase;
|
||||
final GetMapSettingsUsecase getMapSettingsUsecase;
|
||||
final GetNotificationsStreamUseCase getNotificationsStreamUseCase;
|
||||
@@ -35,6 +38,7 @@ class MapBloc extends Bloc<ScooterEvent, ScooterState> {
|
||||
MapBloc(
|
||||
this.getAvailableZonesUsecase,
|
||||
this.getScootersUsecase,
|
||||
this.getClientOrdersUsecase,
|
||||
this.getMapSettingsUsecase,
|
||||
this.getNotificationsStreamUseCase,
|
||||
this.getProfileUseCase,
|
||||
@@ -49,6 +53,9 @@ class MapBloc extends Bloc<ScooterEvent, ScooterState> {
|
||||
on<FetchProfileData>(_onFetchProfileData);
|
||||
on<CheckUser>(_onCheckUser);
|
||||
on<LogoutPressed>(_onLogoutPressed);
|
||||
on<FocusOnScooter>(_onFocusOnScooter);
|
||||
on<ClearMapPlacemarks>(_onClearMapPlacemarks);
|
||||
on<ClearMapFocus>(_onClearMapFocus);
|
||||
}
|
||||
|
||||
void startNotificationStream() {
|
||||
@@ -97,11 +104,15 @@ class MapBloc extends Bloc<ScooterEvent, ScooterState> {
|
||||
getScootersUsecase(event.areaScooters, 0, 100),
|
||||
getAvailableZonesUsecase(event.area, 0, 100),
|
||||
getMapSettingsUsecase(),
|
||||
getClientOrdersUsecase(),
|
||||
]);
|
||||
|
||||
final scooters = results[0] as List<Scooter>;
|
||||
final zones = results[1] as List<Zone>;
|
||||
final settings = results[2] as MapSettings;
|
||||
final orders = results[3];
|
||||
|
||||
|
||||
|
||||
zones.forEach(print);
|
||||
|
||||
@@ -127,6 +138,7 @@ class MapBloc extends Bloc<ScooterEvent, ScooterState> {
|
||||
state.copyWith(
|
||||
status: ScooterStatus.success,
|
||||
scooters: scooters,
|
||||
// reservedScooters: reservedScooters,
|
||||
zones: filteredZones,
|
||||
area: event.area,
|
||||
areaScooters: event.areaScooters,
|
||||
@@ -236,7 +248,9 @@ class MapBloc extends Bloc<ScooterEvent, ScooterState> {
|
||||
try {
|
||||
final profile = await getProfileUseCase();
|
||||
|
||||
emit(state.copyWith(phoneNumber: profile.phone, balance: profile.balance));
|
||||
emit(
|
||||
state.copyWith(phoneNumber: profile.phone, balance: profile.balance),
|
||||
);
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
@@ -280,4 +294,52 @@ class MapBloc extends Bloc<ScooterEvent, ScooterState> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onFocusOnScooter(FocusOnScooter event, Emitter<ScooterState> emit) {
|
||||
final updatedReserved = List<Scooter>.from(state.reservedScooters ?? []);
|
||||
if (!updatedReserved.any((s) => s.id == event.scooter.id)) {
|
||||
updatedReserved.add(event.scooter);
|
||||
}
|
||||
|
||||
emit(state.copyWith(
|
||||
selectedScooterForFocus: event.scooter,
|
||||
reservedScooters: updatedReserved,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
||||
FutureOr<void> _onClearMapPlacemarks(ClearMapPlacemarks event, Emitter<ScooterState> emit) async {
|
||||
try{
|
||||
final orders = await getClientOrdersUsecase();
|
||||
|
||||
List<Scooter> updatedReservedScooters = [];
|
||||
|
||||
if (orders is Success<List<ScooterOrder>>) {
|
||||
print("FETCH: orders.data.length = ${orders.data?.length}");
|
||||
|
||||
updatedReservedScooters = orders.data?.map((order) {
|
||||
return order.scooter;
|
||||
}).toList() ?? [];
|
||||
}
|
||||
|
||||
emit(state.copyWith(
|
||||
reservedScooters: updatedReservedScooters,
|
||||
));
|
||||
} catch (e) {
|
||||
print("Error in _onClearMapPlacemarks: $e");
|
||||
emit(state.copyWith(
|
||||
status: ScooterStatus.failure,
|
||||
errorMessage: e.toString(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onClearMapFocus(ClearMapFocus event, Emitter<ScooterState> emit) {
|
||||
emit(state.copyWith(
|
||||
selectedScooterForFocus: null,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'package:be_happy/domain/entities/scooter_order.dart';
|
||||
import 'package:be_happy/domain/usecase/get_scooter_order_history_usecase.dart';
|
||||
import 'package:be_happy/core/result.dart';
|
||||
|
||||
// 🔹 EVENTS
|
||||
abstract class OrderHistoryEvent {}
|
||||
|
||||
class OrderHistoryFetchRequested extends OrderHistoryEvent {
|
||||
@@ -13,7 +12,6 @@ class OrderHistoryFetchRequested extends OrderHistoryEvent {
|
||||
|
||||
class OrderHistoryRefreshRequested extends OrderHistoryEvent {}
|
||||
|
||||
// 🔹 STATES
|
||||
enum OrderHistoryStatus { initial, loading, success, failure, empty }
|
||||
|
||||
class OrderHistoryState {
|
||||
|
||||
@@ -89,12 +89,11 @@ class PaymentConfirmBloc
|
||||
event.isBalance,
|
||||
);
|
||||
|
||||
if (result is Success<ScooterOrder>) {
|
||||
if (result is Success<void>) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: PaymentConfirmStatus.success,
|
||||
paymentCompleted: true,
|
||||
|
||||
),
|
||||
);
|
||||
} else if (result is Failure) {
|
||||
|
||||
@@ -70,13 +70,16 @@ class PaymentMethodsBloc extends Bloc<PaymentMethodsEvent, PaymentMethodsState>
|
||||
PaymentMethodsDeleteCard event,
|
||||
Emitter<PaymentMethodsState> emit,
|
||||
) async {
|
||||
emit(state.copyWith(isDeleting: true));
|
||||
emit(state.copyWith(
|
||||
status: PaymentMethodsStatus.loading,
|
||||
isDeleting: true,
|
||||
));
|
||||
|
||||
try {
|
||||
final result = await _removePaymentCardUsecase(event.cardId);
|
||||
|
||||
if (result is Success) {
|
||||
emit(state.copyWith(isDeleting: false));
|
||||
emit(state.copyWith(isDeleting: false, status: PaymentMethodsStatus.success));
|
||||
add(PaymentMethodsStarted());
|
||||
} else if (result is Failure) {
|
||||
String errorMessage = 'Не удалось удалить карту';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:be_happy/core/result.dart';
|
||||
import 'package:be_happy/domain/entities/client_subscription.dart';
|
||||
import 'package:be_happy/domain/entities/subscription.dart';
|
||||
import 'package:be_happy/domain/usecase/get_available_subscriptions_usecase.dart';
|
||||
import 'package:be_happy/domain/usecase/get_client_subscriptions_usecase.dart';
|
||||
@@ -11,6 +12,7 @@ class SubscriptionListBloc extends Bloc<SubscriptionEvent, SubscriptionState> {
|
||||
final GetAvailableSubscriptionsUsecase getAvailableSubscriptionsUsecase;
|
||||
final GetClientSubscriptionsUsecase getClientSubscriptionsUsecase;
|
||||
|
||||
|
||||
SubscriptionListBloc({
|
||||
required this.getAvailableSubscriptionsUsecase,
|
||||
required this.getClientSubscriptionsUsecase,
|
||||
@@ -26,10 +28,25 @@ class SubscriptionListBloc extends Bloc<SubscriptionEvent, SubscriptionState> {
|
||||
final allResult = results[0];
|
||||
final activeResult = results[1] ;
|
||||
|
||||
if (allResult is Success<List<Subscription>> && activeResult is Success<List<Subscription>>) {
|
||||
if (allResult is Success<List<Subscription>> && activeResult is Success<List<ClientSubscription>>) {
|
||||
final availableSubs = allResult.data ?? [];
|
||||
final clientSubs = activeResult.data ?? [];
|
||||
|
||||
final Map<int, Subscription> combinedSubsMap = {};
|
||||
|
||||
for (var clientSub in clientSubs) {
|
||||
if (clientSub.subscription != null) {
|
||||
combinedSubsMap[clientSub.subscriptionId] = clientSub.subscription;
|
||||
}
|
||||
}
|
||||
|
||||
for (var sub in availableSubs) {
|
||||
combinedSubsMap[sub.id] = sub;
|
||||
}
|
||||
|
||||
emit(SubscriptionsLoaded(
|
||||
subscriptions: allResult.data ?? [],
|
||||
activeSubscriptions: activeResult.data ?? [],
|
||||
subscriptions: combinedSubsMap.values.toList(),
|
||||
activeSubscriptions: clientSubs,
|
||||
));
|
||||
} else {
|
||||
emit(SubscriptionsError("Не удалось загрузить данные из API"));
|
||||
|
||||
@@ -4,38 +4,59 @@ import 'package:be_happy/domain/usecase/activate_subscription_usecase.dart';
|
||||
import 'package:be_happy/domain/usecase/get_subscription_by_id_usecase.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../domain/entities/client_subscription.dart';
|
||||
import '../../domain/usecase/get_client_subscriptions_usecase.dart';
|
||||
import '../event/subscription_details_event.dart';
|
||||
import '../state/susbcription_details_state.dart';
|
||||
|
||||
class SubscriptionDetailsBloc extends Bloc<SubscriptionDetailsEvent, SubscriptionDetailsState> {
|
||||
class SubscriptionDetailsBloc
|
||||
extends Bloc<SubscriptionDetailsEvent, SubscriptionDetailsState> {
|
||||
final GetSubscriptionByIdUsecase getSubscriptionByIdUsecase;
|
||||
final ActivateSubscriptionUsecase activateSubscriptionUsecase;
|
||||
final GetClientSubscriptionsUsecase getClientSubscriptionsUsecase;
|
||||
|
||||
SubscriptionDetailsBloc(this.getSubscriptionByIdUsecase,
|
||||
this.activateSubscriptionUsecase) : super(DetailsLoading()) {
|
||||
SubscriptionDetailsBloc(
|
||||
this.getSubscriptionByIdUsecase,
|
||||
this.activateSubscriptionUsecase,
|
||||
this.getClientSubscriptionsUsecase,
|
||||
) : super(DetailsLoading()) {
|
||||
on<LoadDetailsEvent>((event, emit) async {
|
||||
emit(DetailsLoading());
|
||||
try {
|
||||
|
||||
final result = await getSubscriptionByIdUsecase(event.subscriptionId);
|
||||
|
||||
switch (result) {
|
||||
final clientSubsResult = await getClientSubscriptionsUsecase();
|
||||
bool isPurchased = false;
|
||||
|
||||
case Success<Subscription>():
|
||||
final sub = result.data;
|
||||
|
||||
if (sub == null) return;
|
||||
|
||||
emit(DetailsContentState(
|
||||
subscription: sub,
|
||||
selectedPeriod: sub.options.first,
|
||||
));
|
||||
case Failure<Subscription>():
|
||||
emit(DetailsError("Ошибка при запросе данных"));
|
||||
switch (clientSubsResult) {
|
||||
case Success<List<ClientSubscription>>():
|
||||
isPurchased = clientSubsResult.data?.any(
|
||||
(element) => element.subscriptionId == event.subscriptionId,
|
||||
) ?? false;
|
||||
break;
|
||||
|
||||
case Failure<List<ClientSubscription>>():
|
||||
isPurchased = false;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (result) {
|
||||
case Success<Subscription>():
|
||||
final sub = result.data;
|
||||
if (sub == null) return;
|
||||
|
||||
emit(
|
||||
DetailsContentState(
|
||||
subscription: sub,
|
||||
selectedPeriod: sub.options.first,
|
||||
isAlreadyPurchased: isPurchased,
|
||||
),
|
||||
);
|
||||
break;
|
||||
case Failure<Subscription>():
|
||||
emit(DetailsError("Ошибка при запросе данных"));
|
||||
break;
|
||||
}
|
||||
} catch (e) {
|
||||
emit(DetailsError("Не удалось загрузить данные"));
|
||||
}
|
||||
@@ -43,7 +64,9 @@ class SubscriptionDetailsBloc extends Bloc<SubscriptionDetailsEvent, Subscriptio
|
||||
|
||||
on<SelectPeriodEvent>((event, emit) {
|
||||
if (state is DetailsContentState) {
|
||||
emit((state as DetailsContentState).copyWith(selectedPeriod: event.period));
|
||||
emit(
|
||||
(state as DetailsContentState).copyWith(selectedPeriod: event.period),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -53,14 +76,23 @@ class SubscriptionDetailsBloc extends Bloc<SubscriptionDetailsEvent, Subscriptio
|
||||
}
|
||||
});
|
||||
|
||||
on<ActivateSubscriptionPressed>((event, emit) {
|
||||
switch(state) {
|
||||
on<ActivateSubscriptionPressed>((event, emit) async {
|
||||
switch (state) {
|
||||
case DetailsContentState contentState:
|
||||
activateSubscriptionUsecase(contentState.selectedPeriod.id);
|
||||
if (!contentState.isAgreed) {
|
||||
return;
|
||||
}
|
||||
|
||||
final result = await activateSubscriptionUsecase(contentState.selectedPeriod.id);
|
||||
|
||||
if (result is Success) {
|
||||
emit(contentState.copyWith(isSuccess: true));
|
||||
} else {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user