fix order history, add CheckUser check before starting the trip, fix dialog for cancel the order, add dialog for finish the order

This commit is contained in:
2026-05-21 18:00:26 +03:00
parent c996d0847f
commit 591265a7fc
6 changed files with 217 additions and 110 deletions

View File

@@ -3,11 +3,8 @@ import 'package:flutter/material.dart';
class CancelBookingDialog extends StatelessWidget { class CancelBookingDialog extends StatelessWidget {
const CancelBookingDialog({super.key}); const CancelBookingDialog({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
bool result = false;
return Dialog( return Dialog(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
insetPadding: const EdgeInsets.symmetric(horizontal: 40), insetPadding: const EdgeInsets.symmetric(horizontal: 40),
@@ -42,6 +39,7 @@ class CancelBookingDialog extends StatelessWidget {
), ),
const SizedBox(height: 24), const SizedBox(height: 24),
// 🔹 Кнопка "Отменить" — ПЕРВАЯ, зелёная (градиент), возвращает true
Container( Container(
width: double.infinity, width: double.infinity,
height: 52, height: 52,
@@ -52,10 +50,7 @@ class CancelBookingDialog extends StatelessWidget {
), ),
), ),
child: ElevatedButton( child: ElevatedButton(
onPressed: () => { onPressed: () => Navigator.pop(context, true), // ✅ true = отменить
result = false,
Navigator.pop(context, result)
},
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
shadowColor: Colors.transparent, shadowColor: Colors.transparent,
@@ -64,9 +59,9 @@ class CancelBookingDialog extends StatelessWidget {
), ),
), ),
child: const Text( child: const Text(
"Оставить", "Отменить",
style: TextStyle( style: TextStyle(
color: Color(0xFF1D273A), color: Color(0xFF1D273A), // тёмный текст на светлом градиенте
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
@@ -74,14 +69,13 @@ class CancelBookingDialog extends StatelessWidget {
), ),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
// 🔹 Кнопка "Оставить" — ВТОРАЯ, тёмная, возвращает false
SizedBox( SizedBox(
width: double.infinity, width: double.infinity,
height: 52, height: 52,
child: ElevatedButton( child: ElevatedButton(
onPressed: () { onPressed: () => Navigator.pop(context, false), // ❌ false = оставить
result = true;
Navigator.pop(context, result);
},
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0D1024), backgroundColor: const Color(0xFF0D1024),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
@@ -89,7 +83,7 @@ class CancelBookingDialog extends StatelessWidget {
), ),
), ),
child: const Text( child: const Text(
"Отменить", "Оставить",
style: TextStyle(color: Colors.white, fontSize: 16), style: TextStyle(color: Colors.white, fontSize: 16),
), ),
), ),

View File

@@ -0,0 +1,96 @@
import 'package:flutter/material.dart';
class FinishRideConfirmationDialog extends StatelessWidget {
const FinishRideConfirmationDialog({super.key});
@override
Widget build(BuildContext context) {
return Dialog(
backgroundColor: Colors.transparent,
insetPadding: const EdgeInsets.symmetric(horizontal: 40),
child: Container(
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: const Color(0xFF2E3253).withOpacity(0.95),
borderRadius: BorderRadius.circular(28),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
"Завершить поездку?",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 22,
fontWeight: FontWeight.w600,
height: 1.2,
),
),
const SizedBox(height: 16),
const Text(
"Вы действительно хотите завершить поездку?",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white70,
fontSize: 14,
height: 1.4,
),
),
const SizedBox(height: 24),
// 🔹 Кнопка "Завершить" — ПЕРВАЯ, зелёная (градиент), возвращает true
Container(
width: double.infinity,
height: 52,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(26),
gradient: const LinearGradient(
colors: [Color(0xFF8EFEB5), Color(0xFF86FEF1)],
),
),
child: ElevatedButton(
onPressed: () => Navigator.pop(context, true), // ✅ true = завершить
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(26),
),
),
child: const Text(
"Завершить",
style: TextStyle(
color: Color(0xFF1D273A), // тёмный текст на светлом градиенте
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
),
const SizedBox(height: 12),
// 🔹 Кнопка "Отмена" — ВТОРАЯ, тёмная, возвращает false
SizedBox(
width: double.infinity,
height: 52,
child: ElevatedButton(
onPressed: () => Navigator.pop(context, false), // ❌ false = отмена
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0D1024),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(26),
),
),
child: const Text(
"Отмена",
style: TextStyle(color: Colors.white, fontSize: 16),
),
),
),
],
),
),
);
}
}

View File

@@ -8,6 +8,7 @@ import '../../../di/service_locator.dart';
import '../../event/active_ride_event.dart'; import '../../event/active_ride_event.dart';
import '../../state/active_ride_state.dart'; import '../../state/active_ride_state.dart';
import '../../viewmodel/active_ride_bloc.dart'; import '../../viewmodel/active_ride_bloc.dart';
import '../dialog/finish_ride_confirmation_dialog.dart';
import '../notification_toast.dart'; import '../notification_toast.dart';
class ActiveRideSheet extends StatefulWidget { class ActiveRideSheet extends StatefulWidget {
@@ -290,32 +291,25 @@ class _ActiveRideSheetState extends State<ActiveRideSheet> {
child: InkWell( child: InkWell(
onTap: state.status == ActiveRideStatus.loading onTap: state.status == ActiveRideStatus.loading
? null ? null
: () { : () async {
_bloc.add(FinishRide(widget.orderId)); // 🔹 Показываем диалог подтверждения
Navigator.pop(context); final result = await showDialog<bool>(
context.go("/home/order-photos/${widget.orderId}"); context: context,
}, builder: (context) => const FinishRideConfirmationDialog(),
borderRadius: BorderRadius.circular(16), );
child: Column(
mainAxisAlignment: MainAxisAlignment.center, // 🔹 Если пользователь подтвердил — завершаем и переходим
children: [ if (result == true) {
const Icon( _bloc.add(FinishRide(widget.orderId));
Icons.stop, Navigator.pop(context); // закрываем ActiveRideSheet
color: Colors.white, context.go("/home/order-photos/${widget.orderId}");
size: 24, }
), // 🔹 Если отменил — ничего не делаем, диалог уже закрылся
const SizedBox(height: 4), },
const Text(
'ЗАВЕРШИТЬ',
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
],
),
), ),
), ),
), ),
), ),

View File

@@ -378,70 +378,41 @@ class _MapScreenState extends State<MapScreen> {
} }
void _onMarkerTap(List<Scooter> scooters) async { void _onMarkerTap(List<Scooter> scooters) async {
final flags = context.read<MapBloc>().state.flags;
if (!flags.hasCard) {
_showExistingNotification(
child: PaymentNotificationCard(
onBindCard: () {
BotToast.cleanAll();
context.push("/home/payment-methods");
},
onClose: () => BotToast.cleanAll(),
),
);
return;
}
if (flags.hasUnpaidOrder) {
_showExistingNotification(
child: UnpaidOrderNotificationCard(
onClose: () => BotToast.cleanAll(),
),
);
return;
}
if (flags.hasFine) {
_showExistingNotification(
child: FineNotificationCard(
onClose: () => BotToast.cleanAll(),
),
);
return;
}
context.push( context.push(
"/home/scooter-sheet", "/home/scooter-sheet",
extra: {'scooters': scooters, 'currentLocation': _currentPosition}, extra: {'scooters': scooters, 'currentLocation': _currentPosition},
); );
/*final scoot = await showModalBottomSheet<Scooter>(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
isDismissible: true,
builder: (context) {
return BlocProvider(
create: (context) =>
ScooterDetailModalBloc(
getIt<GetAddressByPointUsecase>(),
getIt<GetScooterUsecase>(),
getIt<GetPedestrianRoutesUsecase>(),
)..add(
ScooterDetailModalStarted(
scooters,
_currentPosition!.latitude,
_currentPosition!.longitude,
),
),
child: ScooterBottomSheet(),
);
},
);*/
/*bool? isBooking = false;
if (scoot != null) {
final result = await context.push('/home/scooter/${scoot.id}');
if (result == true) {
// Даем небольшую задержку, чтобы навигация завершилась корректно
await Future.delayed(Duration(milliseconds: 300), () async {
isBooking = await showModalBottomSheet<bool>(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
isDismissible: true,
builder: (context) => BlocProvider(
create: (context) => TariffSheetBloc(
getIt<GetAvailableTariffsUsecase>(),
getIt<GetPaymentCardsUsecase>(),
getIt<BookScooterUsecase>(),
),
child: TariffSheet(scooter: scoot),
),
);
});
}
}
if (isBooking ?? false) {
showModalBottomSheet(
context: context,
builder: (context) => BlocProvider(
create: (context) =>
CurrentRidesBloc(getIt<GetClientOrdersUsecase>())
..add(LoadClientOrders(1)),
child: CurrentRidesSheet(clientId: 1),
),
);
}*/
} }
void _onMapSettingsTap() { void _onMapSettingsTap() {
@@ -717,7 +688,42 @@ class _MapScreenState extends State<MapScreen> {
right: 0, right: 0,
child: Center( child: Center(
child: GestureDetector( child: GestureDetector(
onTap: () => context.push("/home/qr-info"), onTap: () {
final flags = context.read<MapBloc>().state.flags;
// 🔹 Проверка флагов — показываем те же карточки, что и в listener
if (!flags.hasCard) {
_showExistingNotification(
child: PaymentNotificationCard(
onBindCard: () {
BotToast.cleanAll();
context.push("/home/payment-methods");
},
onClose: () => BotToast.cleanAll(),
),
);
return;
}
if (flags.hasUnpaidOrder) {
_showExistingNotification(
child: UnpaidOrderNotificationCard(
onClose: () => BotToast.cleanAll(),
),
);
return;
}
if (flags.hasFine) {
_showExistingNotification(
child: FineNotificationCard(
onClose: () => BotToast.cleanAll(),
),
);
return;
}
// ✅ Все проверки пройдены — переход на сканирование
context.push("/home/qr-info");
},
child: Container( child: Container(
width: 64, width: 64,
height: 64, height: 64,
@@ -866,3 +872,18 @@ class _CircleIconButton extends StatelessWidget {
); );
} }
} }
void _showExistingNotification({required Widget child}) {
BotToast.showCustomNotification(
duration: null, // не исчезает, пока пользователь не закроет
toastBuilder: (_) {
return Container(
margin: const EdgeInsets.only(top: 120), // тот же отступ, что в listener
child: Material(
color: Colors.transparent,
child: child, // PaymentNotificationCard / UnpaidOrderNotificationCard / FineNotificationCard
),
);
},
);
}

View File

@@ -102,6 +102,7 @@ class ScooterDetailScreen extends StatelessWidget {
context.pushReplacement('/home/tarif-sheet', extra: scooter); context.pushReplacement('/home/tarif-sheet', extra: scooter);
}, },
), ),
const SizedBox(height: 30)
], ],
), ),
), ),

View File

@@ -21,14 +21,14 @@ class OrderHistoryState {
final List<ScooterOrder> orders; final List<ScooterOrder> orders;
final String? errorMessage; final String? errorMessage;
final int currentPage; final int currentPage;
final bool hasMore; final bool hasMore; // можно оставить, но всегда будет false
OrderHistoryState({ OrderHistoryState({
required this.status, required this.status,
this.orders = const [], this.orders = const [],
this.errorMessage, this.errorMessage,
this.currentPage = 1, this.currentPage = 1,
this.hasMore = true, this.hasMore = false, // ✅ По умолчанию — нет больше данных
}); });
OrderHistoryState copyWith({ OrderHistoryState copyWith({
@@ -51,7 +51,8 @@ class OrderHistoryState {
class OrderHistoryBloc extends Bloc<OrderHistoryEvent, OrderHistoryState> { class OrderHistoryBloc extends Bloc<OrderHistoryEvent, OrderHistoryState> {
final GetScooterOrderHistoryUsecase _usecase; final GetScooterOrderHistoryUsecase _usecase;
OrderHistoryBloc(this._usecase) : super(OrderHistoryState(status: OrderHistoryStatus.initial)) { OrderHistoryBloc(this._usecase)
: super(OrderHistoryState(status: OrderHistoryStatus.initial)) {
on<OrderHistoryFetchRequested>(_onFetchRequested); on<OrderHistoryFetchRequested>(_onFetchRequested);
on<OrderHistoryRefreshRequested>(_onRefreshRequested); on<OrderHistoryRefreshRequested>(_onRefreshRequested);
} }
@@ -64,9 +65,11 @@ class OrderHistoryBloc extends Bloc<OrderHistoryEvent, OrderHistoryState> {
emit(state.copyWith(status: OrderHistoryStatus.loading)); emit(state.copyWith(status: OrderHistoryStatus.loading));
} }
final result = await _usecase.call(page: event.page); final result = await _usecase.call(
page: event.page,
pageSize: 1000,
);
// ✅ Явная проверка с правильным типом
if (result is Success<List<ScooterOrder>>) { if (result is Success<List<ScooterOrder>>) {
final orders = result.data; final orders = result.data;
@@ -84,12 +87,10 @@ class OrderHistoryBloc extends Bloc<OrderHistoryEvent, OrderHistoryState> {
status: OrderHistoryStatus.success, status: OrderHistoryStatus.success,
orders: newOrders, orders: newOrders,
currentPage: event.page, currentPage: event.page,
hasMore: orders.length == 20, hasMore: false,
)); ));
} }
} } else if (result is Failure<List<ScooterOrder>>) {
// ✅ Явно указываем тип Failure
else if (result is Failure<List<ScooterOrder>>) {
emit(state.copyWith( emit(state.copyWith(
status: OrderHistoryStatus.failure, status: OrderHistoryStatus.failure,
errorMessage: result.failure.message ?? 'Неизвестная ошибка', errorMessage: result.failure.message ?? 'Неизвестная ошибка',