112 lines
3.1 KiB
Dart
112 lines
3.1 KiB
Dart
import 'package:equatable/equatable.dart';
|
|
import '../data/models/trip_model.dart';
|
|
|
|
/// هل هذه الحالة نهائية (لا انتقالات منها)?
|
|
bool isTerminalStatus(String status) {
|
|
return status == 'cancelled' || status == 'no_drivers' || status == 'expired' || status == 'paid';
|
|
}
|
|
|
|
/// حالة TripBloc الموحدة.
|
|
class TripState extends Equatable {
|
|
final TripRequestStatus requestStatus;
|
|
final TripModel? trip;
|
|
final String? driverName;
|
|
final String? vehicleMake;
|
|
final String? vehicleModel;
|
|
final String? vehiclePlate;
|
|
final String? vehicleColor;
|
|
final double? driverLat;
|
|
final double? driverLng;
|
|
final double? driverHeading;
|
|
final String? error;
|
|
final bool rated;
|
|
|
|
const TripState({
|
|
this.requestStatus = TripRequestStatus.idle,
|
|
this.trip,
|
|
this.driverName,
|
|
this.vehicleMake,
|
|
this.vehicleModel,
|
|
this.vehiclePlate,
|
|
this.vehicleColor,
|
|
this.driverLat,
|
|
this.driverLng,
|
|
this.driverHeading,
|
|
this.error,
|
|
this.rated = false,
|
|
});
|
|
|
|
TripState copyWith({
|
|
TripRequestStatus? requestStatus,
|
|
TripModel? trip,
|
|
String? driverName,
|
|
String? vehicleMake,
|
|
String? vehicleModel,
|
|
String? vehiclePlate,
|
|
String? vehicleColor,
|
|
double? driverLat,
|
|
double? driverLng,
|
|
double? driverHeading,
|
|
String? error,
|
|
bool? rated,
|
|
bool clearError = false,
|
|
bool clearDriver = false,
|
|
}) {
|
|
return TripState(
|
|
requestStatus: requestStatus ?? this.requestStatus,
|
|
trip: trip ?? this.trip,
|
|
driverName: clearDriver ? null : (driverName ?? this.driverName),
|
|
vehicleMake: clearDriver ? null : (vehicleMake ?? this.vehicleMake),
|
|
vehicleModel: clearDriver ? null : (vehicleModel ?? this.vehicleModel),
|
|
vehiclePlate: clearDriver ? null : (vehiclePlate ?? this.vehiclePlate),
|
|
vehicleColor: clearDriver ? null : (vehicleColor ?? this.vehicleColor),
|
|
driverLat: driverLat ?? this.driverLat,
|
|
driverLng: driverLng ?? this.driverLng,
|
|
driverHeading: driverHeading ?? this.driverHeading,
|
|
error: clearError ? null : (error ?? this.error),
|
|
rated: rated ?? this.rated,
|
|
);
|
|
}
|
|
|
|
/// هل هناك رحلة نشطة (ليست idle ولا terminal)?
|
|
bool get hasActiveTrip =>
|
|
trip != null &&
|
|
requestStatus != TripRequestStatus.idle &&
|
|
!isTerminalStatus(trip!.status);
|
|
|
|
/// هل يمكن إلغاء الرحلة حالياً?
|
|
bool get canCancel {
|
|
if (trip == null) return false;
|
|
return ['searching', 'assigned', 'driver_arriving', 'driver_arrived']
|
|
.contains(trip!.status);
|
|
}
|
|
|
|
/// هل يمكن للمستخدم ركوب الرحلة (اكتملت)?
|
|
bool get isCompleted => trip?.status == 'completed' || trip?.status == 'paid';
|
|
|
|
@override
|
|
List<Object?> get props => [
|
|
requestStatus,
|
|
trip,
|
|
driverName,
|
|
vehicleMake,
|
|
vehicleModel,
|
|
vehiclePlate,
|
|
vehicleColor,
|
|
driverLat,
|
|
driverLng,
|
|
driverHeading,
|
|
error,
|
|
rated,
|
|
];
|
|
}
|
|
|
|
enum TripRequestStatus {
|
|
idle,
|
|
loading,
|
|
searching,
|
|
active, // assigned → in_progress
|
|
completed,
|
|
error,
|
|
}
|