sync changes
This commit is contained in:
@@ -57,8 +57,6 @@ class ActiveRideBloc extends Bloc<ActiveRideEvent, ActiveRideState> {
|
||||
if (orderResult is Success<ScooterOrder>) {
|
||||
final order = orderResult.data;
|
||||
|
||||
|
||||
// Пытаемся достать доп. данные, если они Success
|
||||
final orderData = activeOrderData is Success<ActiveScooterOrder>
|
||||
? activeOrderData.data
|
||||
: null;
|
||||
@@ -80,7 +78,6 @@ class ActiveRideBloc extends Bloc<ActiveRideEvent, ActiveRideState> {
|
||||
inZone: orderData?.zone,
|
||||
));
|
||||
|
||||
//synchronize
|
||||
_syncTimer?.cancel();
|
||||
_syncTimer = Timer.periodic(const Duration(seconds: 5), (timer) {
|
||||
add(SyncScooterOrder(event.orderId));
|
||||
|
||||
@@ -20,6 +20,8 @@ class CurrentRidesBloc extends Bloc<CurrentRidesEvent, CurrentRidesState> {
|
||||
) async {
|
||||
emit(state.copyWith(status: CurrentRidesStatus.loading));
|
||||
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
|
||||
final result = await _getClientOrdersUsecase();
|
||||
|
||||
if (result is Success<List<ScooterOrder>>) {
|
||||
|
||||
@@ -55,10 +55,11 @@ class ScooterDetailModalBloc
|
||||
|
||||
final routes = await _getPedestrianRoutesUsecase(
|
||||
Point(latitude: event.userLatitude, longitude: event.userLongitude),
|
||||
Point(latitude: scooter.latitude, longitude: scooter.longitude),
|
||||
Point(latitude: scooter.longitude, longitude: scooter.latitude),
|
||||
);
|
||||
|
||||
final distance = routes?.firstOrNull?.metadata.weight.walkingDistance.value;
|
||||
print("Distance is: $distance");
|
||||
final time = routes?.firstOrNull?.metadata.weight.time.value;
|
||||
|
||||
if (result is Success<Scooter>) {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'package:be_happy/core/failures.dart';
|
||||
import 'package:be_happy/domain/entities/scooter_order.dart';
|
||||
import 'package:be_happy/domain/usecase/get_profile_usecase.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
@@ -29,6 +31,7 @@ class TariffSheetBloc extends Bloc<TariffSheetEvent, TariffSheetState> {
|
||||
on<PaymentCardChanged>(_onPaymentCardChanged);
|
||||
on<BookScooterPressed>(_onBookScooterPressed);
|
||||
on<SelectBalancePressed>(_onSelectBalancePressed);
|
||||
on<InsuranceToggled>(_onInsuranceToggled);
|
||||
}
|
||||
|
||||
Future<void> _onStarted(
|
||||
@@ -92,12 +95,12 @@ class TariffSheetBloc extends Bloc<TariffSheetEvent, TariffSheetState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onBookScooterPressed(
|
||||
FutureOr<void> _onBookScooterPressed (
|
||||
BookScooterPressed event,
|
||||
Emitter<TariffSheetState> emit,
|
||||
) {
|
||||
) async {
|
||||
try {
|
||||
_bookScooterUsecase(
|
||||
final result = await _bookScooterUsecase(
|
||||
scooterId: event.scooterId,
|
||||
planId: event.planId,
|
||||
cardId: event.cardId,
|
||||
@@ -105,7 +108,23 @@ class TariffSheetBloc extends Bloc<TariffSheetEvent, TariffSheetState> {
|
||||
isBalance: event.isBalance,
|
||||
isInsurance: event.isInsurance,
|
||||
);
|
||||
Future.delayed(const Duration(milliseconds: 300));
|
||||
|
||||
switch (result) {
|
||||
|
||||
case Success<ScooterOrder>():
|
||||
// TODO: Handle this case.
|
||||
throw UnimplementedError();
|
||||
case Failure<ScooterOrder>():
|
||||
if (result is WrongZoneFailure) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: TariffSheetStatus.failure,
|
||||
errorMessage: result.failure.message,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
@@ -125,4 +144,8 @@ class TariffSheetBloc extends Bloc<TariffSheetEvent, TariffSheetState> {
|
||||
selectedCard: null,
|
||||
));
|
||||
}
|
||||
|
||||
FutureOr<void> _onInsuranceToggled(InsuranceToggled event, Emitter<TariffSheetState> emit) async {
|
||||
emit(state.copyWith(isInsurance: event.isEnabled));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user