25-6-23/1
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
// lib/models/order_data.dart
|
||||
// lib/models/model/order_data.dart
|
||||
|
||||
class OrderData {
|
||||
final String customerName;
|
||||
final double tripDistanceKm; // المسافة الكلية للرحلة بالكيلومتر
|
||||
final String customerToken;
|
||||
final double tripDistanceKm; // The total trip distance in kilometers
|
||||
final String price;
|
||||
final String startLocationAddress;
|
||||
final String endLocationAddress;
|
||||
|
||||
final double distanceToPassengerKm; // المسافة إلى الراكب بالكيلومتر
|
||||
final int tripDurationMinutes; // مدة الرحلة الكلية بالدقائق (مقربة لأعلى)
|
||||
final double
|
||||
distanceToPassengerKm; // The distance to the passenger in kilometers
|
||||
final int tripDurationMinutes; // Total trip duration in minutes (rounded up)
|
||||
final int
|
||||
durationToPassengerMinutes; // المدة إلى الراكب بالدقائق (مقربة لأعلى)
|
||||
durationToPassengerMinutes; // Duration to reach the passenger in minutes (rounded up)
|
||||
|
||||
final String rideType;
|
||||
final String orderId;
|
||||
@@ -22,6 +24,7 @@ class OrderData {
|
||||
|
||||
OrderData({
|
||||
required this.customerName,
|
||||
required this.customerToken,
|
||||
required this.tripDistanceKm,
|
||||
required this.price,
|
||||
required this.startLocationAddress,
|
||||
@@ -37,26 +40,57 @@ class OrderData {
|
||||
this.rawEndCoordinates,
|
||||
});
|
||||
|
||||
// دالة مساعدة لتحويل الثواني إلى دقائق وتقريبها لأعلى
|
||||
// --- NEW: Factory constructor to create an instance from a Map ---
|
||||
// This is the missing method that was causing the error.
|
||||
factory OrderData.fromMap(Map<String, dynamic> map) {
|
||||
return OrderData(
|
||||
// For strings, provide a default value in case the map key is null
|
||||
customerName: map['customerName']?.toString() ?? 'Unknown Customer',
|
||||
customerToken: map['customerToken']?.toString() ?? 'Unknown token',
|
||||
|
||||
// For numbers, cast from 'num' to handle both int and double, with a default value
|
||||
tripDistanceKm: (map['tripDistanceKm'] as num?)?.toDouble() ?? 0.0,
|
||||
|
||||
price: map['price']?.toString() ?? '0',
|
||||
startLocationAddress:
|
||||
map['startLocationAddress']?.toString() ?? 'Unknown Address',
|
||||
endLocationAddress:
|
||||
map['endLocationAddress']?.toString() ?? 'Unknown Address',
|
||||
|
||||
distanceToPassengerKm:
|
||||
(map['distanceToPassengerKm'] as num?)?.toDouble() ?? 0.0,
|
||||
|
||||
tripDurationMinutes: (map['tripDurationMinutes'] as num?)?.toInt() ?? 0,
|
||||
durationToPassengerMinutes:
|
||||
(map['durationToPassengerMinutes'] as num?)?.toInt() ?? 0,
|
||||
|
||||
rideType: map['rideType']?.toString() ?? 'Unknown',
|
||||
orderId: map['orderId']?.toString() ?? 'N/A',
|
||||
passengerId: map['passengerId']?.toString() ?? 'N/A',
|
||||
passengerRate: map['passengerRate']?.toString() ?? 'N/A',
|
||||
|
||||
// For nullable strings, direct access is fine as it returns null if the key doesn't exist
|
||||
rawStartCoordinates: map['rawStartCoordinates'],
|
||||
rawEndCoordinates: map['rawEndCoordinates'],
|
||||
);
|
||||
}
|
||||
|
||||
// A helper function to convert seconds to rounded-up minutes
|
||||
static int _secondsToRoundedUpMinutes(String secondsString) {
|
||||
final seconds = double.tryParse(secondsString) ?? 0.0;
|
||||
if (seconds <= 0) return 0;
|
||||
return (seconds / 60)
|
||||
.ceil(); // .ceil() لتقريب الكسر لأعلى (مثلاً 0.1 دقيقة تصبح 1 دقيقة)
|
||||
.ceil(); // .ceil() rounds up (e.g., 0.1 minutes becomes 1 minute)
|
||||
}
|
||||
|
||||
// Your existing factory for creating an instance from a List
|
||||
factory OrderData.fromList(List<dynamic> list) {
|
||||
// بناءً على testList والافتراضات الجديدة:
|
||||
// list[4]: durationToRide (مدة الرحلة الكلية بالثواني)
|
||||
// list[5]: distance (المسافة الكلية للرحلة بالكيلومتر)
|
||||
// list[12]: distanceByPassenger (المسافة إلى الراكب بالمتر)
|
||||
// list[15]: durationToPassenger (المدة إلى الراكب بالثواني)
|
||||
|
||||
double distanceToPassengerMeters =
|
||||
list.length > 12 ? (double.tryParse(list[12].toString()) ?? 0.0) : 0.0;
|
||||
|
||||
return OrderData(
|
||||
customerName: list.length > 8 ? list[8].toString() : 'Unknown Customer',
|
||||
customerToken: list.length > 9 ? list[9].toString() : 'Unknown token',
|
||||
tripDistanceKm:
|
||||
list.length > 5 ? (double.tryParse(list[5].toString()) ?? 0.0) : 0.0,
|
||||
price: list.length > 2 ? list[2].toString().split('.')[0] : '0',
|
||||
@@ -66,7 +100,7 @@ class OrderData {
|
||||
list.length > 30 ? list[30].toString() : 'Unknown Address',
|
||||
|
||||
distanceToPassengerKm:
|
||||
distanceToPassengerMeters / 1000.0, // تحويل من متر إلى كيلومتر
|
||||
distanceToPassengerMeters / 1000.0, // Convert meters to kilometers
|
||||
|
||||
tripDurationMinutes:
|
||||
list.length > 4 ? _secondsToRoundedUpMinutes(list[4].toString()) : 0,
|
||||
@@ -102,6 +136,7 @@ class OrderData {
|
||||
}
|
||||
}
|
||||
|
||||
// Getter to parse start coordinates
|
||||
Map<String, double?>? get startCoordinates {
|
||||
if (rawStartCoordinates == null) return null;
|
||||
final parts = rawStartCoordinates!.split(',');
|
||||
@@ -114,6 +149,7 @@ class OrderData {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Getter to parse end coordinates
|
||||
Map<String, double?>? get endCoordinates {
|
||||
if (rawEndCoordinates == null) return null;
|
||||
final parts = rawEndCoordinates!.split(',');
|
||||
@@ -126,6 +162,8 @@ class OrderData {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Your existing method to convert the object TO a Map.
|
||||
// This is used to pass the data from the overlay to the main app.
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'customerName': customerName,
|
||||
|
||||
Reference in New Issue
Block a user