feat: implement core architecture, design system, localization, and trip features for both driver and rider apps.
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// نموذج بيانات السائق — من `GET /drivers/me`.
|
||||
class DriverProfileModel extends Equatable {
|
||||
final String id;
|
||||
final String phone;
|
||||
final String? name;
|
||||
final bool online;
|
||||
final double? lat;
|
||||
final double? lng;
|
||||
final String? vehicleMake;
|
||||
final String? vehicleModel;
|
||||
final int? vehicleYear;
|
||||
final String? vehicleColor;
|
||||
final String? plateNumber;
|
||||
final String? serviceClass;
|
||||
final double? rating;
|
||||
final int? totalTrips;
|
||||
final int? creditBalance;
|
||||
|
||||
const DriverProfileModel({
|
||||
required this.id,
|
||||
required this.phone,
|
||||
this.name,
|
||||
this.online = false,
|
||||
this.lat,
|
||||
this.lng,
|
||||
this.vehicleMake,
|
||||
this.vehicleModel,
|
||||
this.vehicleYear,
|
||||
this.vehicleColor,
|
||||
this.plateNumber,
|
||||
this.serviceClass,
|
||||
this.rating,
|
||||
this.totalTrips,
|
||||
this.creditBalance,
|
||||
});
|
||||
|
||||
factory DriverProfileModel.fromJson(Map<String, dynamic> j) =>
|
||||
DriverProfileModel(
|
||||
id: j['id'] as String,
|
||||
phone: (j['phone'] ?? '') as String,
|
||||
name: j['name'] as String?,
|
||||
online: j['online'] as bool? ?? false,
|
||||
lat: (j['lat'] as num?)?.toDouble(),
|
||||
lng: (j['lng'] as num?)?.toDouble(),
|
||||
vehicleMake: j['vehicleMake'] as String?,
|
||||
vehicleModel: j['vehicleModel'] as String?,
|
||||
vehicleYear: j['vehicleYear'] as int?,
|
||||
vehicleColor: j['vehicleColor'] as String?,
|
||||
plateNumber: j['plateNumber'] as String?,
|
||||
serviceClass: j['serviceClass'] as String?,
|
||||
rating: (j['rating'] as num?)?.toDouble(),
|
||||
totalTrips: j['totalTrips'] as int?,
|
||||
creditBalance: j['creditBalance'] as int?,
|
||||
);
|
||||
|
||||
DriverProfileModel copyWith({
|
||||
String? name,
|
||||
bool? online,
|
||||
double? lat,
|
||||
double? lng,
|
||||
String? vehicleMake,
|
||||
String? vehicleModel,
|
||||
int? vehicleYear,
|
||||
String? vehicleColor,
|
||||
String? plateNumber,
|
||||
String? serviceClass,
|
||||
double? rating,
|
||||
int? totalTrips,
|
||||
int? creditBalance,
|
||||
}) {
|
||||
return DriverProfileModel(
|
||||
id: id,
|
||||
phone: phone,
|
||||
name: name ?? this.name,
|
||||
online: online ?? this.online,
|
||||
lat: lat ?? this.lat,
|
||||
lng: lng ?? this.lng,
|
||||
vehicleMake: vehicleMake ?? this.vehicleMake,
|
||||
vehicleModel: vehicleModel ?? this.vehicleModel,
|
||||
vehicleYear: vehicleYear ?? this.vehicleYear,
|
||||
vehicleColor: vehicleColor ?? this.vehicleColor,
|
||||
plateNumber: plateNumber ?? this.plateNumber,
|
||||
serviceClass: serviceClass ?? this.serviceClass,
|
||||
rating: rating ?? this.rating,
|
||||
totalTrips: totalTrips ?? this.totalTrips,
|
||||
creditBalance: creditBalance ?? this.creditBalance,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, phone, name, online, vehicleMake, vehicleModel, plateNumber];
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// عرض رحلة وارد — من `trip:offer` عبر WebSocket.
|
||||
///
|
||||
/// يحتوي على كل المعلومات التي يحتاجها السائق للقبول/الرفض.
|
||||
/// المهلة الزمنية (`expiresAt`) تُدار من OffersBloc.
|
||||
class TripOfferModel extends Equatable {
|
||||
final String tripId;
|
||||
final double pickupLat;
|
||||
final double pickupLng;
|
||||
final String? pickupAddress;
|
||||
final double dropoffLat;
|
||||
final double dropoffLng;
|
||||
final String? dropoffAddress;
|
||||
final double distance;
|
||||
final num fare;
|
||||
final String currency;
|
||||
final int etaPickup;
|
||||
final String vehicleClass;
|
||||
final DateTime expiresAt;
|
||||
|
||||
const TripOfferModel({
|
||||
required this.tripId,
|
||||
required this.pickupLat,
|
||||
required this.pickupLng,
|
||||
this.pickupAddress,
|
||||
required this.dropoffLat,
|
||||
required this.dropoffLng,
|
||||
this.dropoffAddress,
|
||||
required this.distance,
|
||||
required this.fare,
|
||||
required this.currency,
|
||||
required this.etaPickup,
|
||||
required this.vehicleClass,
|
||||
required this.expiresAt,
|
||||
});
|
||||
|
||||
factory TripOfferModel.fromJson(Map<String, dynamic> j) => TripOfferModel(
|
||||
tripId: j['tripId'] as String,
|
||||
pickupLat: (j['pickup']?['lat'] ?? 0).toDouble(),
|
||||
pickupLng: (j['pickup']?['lng'] ?? 0).toDouble(),
|
||||
pickupAddress: j['pickup']?['address'] as String?,
|
||||
dropoffLat: (j['dropoff']?['lat'] ?? 0).toDouble(),
|
||||
dropoffLng: (j['dropoff']?['lng'] ?? 0).toDouble(),
|
||||
dropoffAddress: j['dropoff']?['address'] as String?,
|
||||
distance: (j['distance'] ?? 0).toDouble(),
|
||||
fare: (j['fare'] ?? 0) as num,
|
||||
currency: (j['currency'] ?? 'IQD') as String,
|
||||
etaPickup: (j['etaPickup'] ?? 0) as int,
|
||||
vehicleClass: (j['vehicleClass'] ?? '') as String,
|
||||
expiresAt: DateTime.parse(j['expiresAt'] as String),
|
||||
);
|
||||
|
||||
/// المسافة المنسقة (كم مع خانتين عشريتين).
|
||||
String get formattedDistance => '${distance.toStringAsFixed(1)} km';
|
||||
|
||||
/// الأجرة المنسقة.
|
||||
String get formattedFare => '$fare $currency';
|
||||
|
||||
@override
|
||||
List<Object?> get props => [tripId, pickupLat, pickupLng, fare, expiresAt];
|
||||
}
|
||||
Reference in New Issue
Block a user