feat: implement core architecture, design system, localization, and trip features for both driver and rider apps.
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import 'dart:async';
|
||||
import '../../home/data/models/trip_offer_model.dart';
|
||||
|
||||
/// تحديث حالة رحلة من WebSocket (للسائق).
|
||||
class DriverTripUpdate {
|
||||
final String tripId;
|
||||
final String status;
|
||||
final Map<String, dynamic> extra;
|
||||
|
||||
const DriverTripUpdate({
|
||||
required this.tripId,
|
||||
required this.status,
|
||||
this.extra = const {},
|
||||
});
|
||||
}
|
||||
|
||||
/// محول أحداث WebSocket للسائق — يدعم:
|
||||
/// - عروض الرحلات (`trip:offer`)
|
||||
/// - إلغاء العروض (`trip:offer_taken`)
|
||||
/// - تحديثات الحالة (`trip:update`)
|
||||
/// - رحلات جديدة (`trip:new`)
|
||||
///
|
||||
/// التصفية الصامتة تتم بترتيب الحالات (docs/23 §15).
|
||||
int _statusOrder(String s) {
|
||||
switch (s) {
|
||||
case 'assigned':
|
||||
return 0;
|
||||
case 'driver_arriving':
|
||||
return 1;
|
||||
case 'driver_arrived':
|
||||
return 2;
|
||||
case 'in_progress':
|
||||
return 3;
|
||||
case 'completed':
|
||||
return 4;
|
||||
case 'paid':
|
||||
return 5;
|
||||
default:
|
||||
return -1; // cancelled, expired
|
||||
}
|
||||
}
|
||||
|
||||
class DriverTripEventMerger {
|
||||
final _offerController = StreamController<TripOfferModel>.broadcast();
|
||||
final _offerTakenController = StreamController<String>.broadcast();
|
||||
final _updateController = StreamController<DriverTripUpdate>.broadcast();
|
||||
final _newTripController = StreamController<String>.broadcast();
|
||||
|
||||
/// الحالة المعروضة حالياً لكل رحلة.
|
||||
final Map<String, int> _currentOrder = {};
|
||||
|
||||
Stream<TripOfferModel> get offerStream => _offerController.stream;
|
||||
Stream<String> get offerTakenStream => _offerTakenController.stream;
|
||||
Stream<DriverTripUpdate> get updateStream => _updateController.stream;
|
||||
Stream<String> get newTripStream => _newTripController.stream;
|
||||
|
||||
/// استقبال عرض رحلة وارد.
|
||||
void addOffer(TripOfferModel offer) {
|
||||
_offerController.add(offer);
|
||||
}
|
||||
|
||||
/// العرض تم قبوله من سائق آخر.
|
||||
void addOfferTaken(String tripId) {
|
||||
_offerTakenController.add(tripId);
|
||||
}
|
||||
|
||||
/// تحديث حالة رحلة نشطة.
|
||||
void addUpdate(DriverTripUpdate update) {
|
||||
final newOrder = _statusOrder(update.status);
|
||||
final currentOrder = _currentOrder[update.tripId] ?? -1;
|
||||
|
||||
if (newOrder >= 0 && newOrder <= currentOrder) return;
|
||||
|
||||
if (newOrder >= 0) {
|
||||
_currentOrder[update.tripId] = newOrder;
|
||||
}
|
||||
|
||||
_updateController.add(update);
|
||||
}
|
||||
|
||||
/// إشعار برحلة جديدة متاحة.
|
||||
void addNewTrip(String tripId) {
|
||||
_newTripController.add(tripId);
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_offerController.close();
|
||||
_offerTakenController.close();
|
||||
_updateController.close();
|
||||
_newTripController.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user