Files
tripz-llc/apps/rider_new/lib/features/trip/cubit/ride_state.dart
T
Hamza-AyedandClaude Opus 5 bb2c0de478 feat(apps): تسجيل السائق والدردشة والكوبون — إكمال التغطية
فحص آليّ لنقاط docs/38 مقابل الكود كشف ثغرات لم تظهر بالقراءة.

## تسجيل السائق — أخطر ثغرة
لم يكن موجوداً أصلاً: سائق جديد يسجّل دخوله ثم يقف. بُنيت features/onboarding
كاملة — تقديم ← ملف ← مركبة ← وثائق ← انتظار الاعتماد.
- الخطوة تُشتقّ من حالة الخادم لا من تقدّم محلّي: سائق يعيد تثبيت التطبيق
  يعود إلى حيث وقف لا إلى البداية
- الاعتماد يقع على الخادم تلقائياً حين تكتمل الوثائق؛ التطبيق لا يعتمد أحداً
- عند الاعتماد خروج إجباري: الدور يتغيّر على الخادم والتوكن القديم يحمل
  القديم، فتفشل نقاط السائق بـ403 (مصيدة docs/38 §5)
- بوابة توجيه: مستخدم دوره ليس driver يُحجز في /onboarding
- الوثائق تُصوَّر بالكاميرا لا من المعرض: أصعب تزويراً

## الدردشة والكوبون
- Features.chat كان مفعّلاً بلا ميزة. features/chat باستطلاع كل خمس ثوان —
  قائمة أحداث الخادم لا تتضمّن الرسائل (docs/38 §9)، فالاستطلاع قيد خادم لا
  اختيار تصميمي
- الكوبون: حقل في ورقة التأكيد خلف طبقتَي الميزات، يُقيَّم على الخادم

## Features.calls أُطفئ صراحةً
الخادم يدعم WebRTC والتطبيق لا. عَلَم مفعّل بلا ميزة كذبٌ على القارئ التالي.

## بنية
- ApiClient.upload للرفع متعدّد الأجزاء
- AuthFailure → ApiFailure في core/api: يخدم المصادقة والملف والتسجيل
- tool/sync_from_rider.sh: المزامنة اليدوية بين التوأمين انكسرت أربع مرات،
  فصارت سكربتاً واحداً يعرّف ما يملكه كل تطبيق

flutter analyze نظيف · الراكب 101 ملف/7,809 سطر · السائق 110 ملف/8,116 سطر.
فحوص آلية: صفر استيراد بين ميزتين · صفر عَلَم مفعّل بلا ميزة · كل نقاط العقد
المخصّصة للتطبيقين مستهلكة.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 00:04:28 +03:00

178 lines
4.8 KiB
Dart

import 'package:equatable/equatable.dart';
import '../data/models/fare_quote.dart';
import '../data/models/geo_point.dart';
import '../data/models/place.dart';
import '../data/models/ride_type.dart';
import '../data/models/route_info.dart';
import '../data/models/trip.dart';
/// مراحل شاشة الراكب. المرحلة تحدّد ما يُعرض على الخريطة وما في الورقة
/// السفلية — «الشاشة مهمة واحدة» (docs/26 §8.1).
enum RidePhase {
/// الخريطة والبطاقة المطوية «إلى أين؟».
idle,
/// المخطّط الموسّع: المصدر والوجهة والمحطات.
planning,
/// المستخدم يحرّك الخريطة والدبّوس ثابت في المنتصف.
pickingOnMap,
/// المسار والتسعيرة معروضان بانتظار التأكيد.
confirming,
/// البحث عن سائق.
searching,
/// رحلة جارية.
active,
}
/// أيّ حقلٍ يلتقط اختيار الخريطة.
enum PickTarget { origin, destination }
enum RideError { none, noDrivers, quoteFailed, routeFailed, requestFailed }
class RideState extends Equatable {
const RideState({
this.phase = RidePhase.idle,
this.origin,
this.destination,
this.originLabel = '',
this.destinationLabel = '',
this.stops = const [],
this.rideTypes = const [],
this.selectedRideType,
this.route,
this.quote,
this.trip,
this.driverLocation,
this.searchResults = const [],
this.searching = false,
this.busy = false,
this.error = RideError.none,
this.pickTarget = PickTarget.destination,
this.cameraTarget,
this.couponCode = '',
});
final RidePhase phase;
final GeoPoint? origin;
final GeoPoint? destination;
final String originLabel;
final String destinationLabel;
final List<GeoPoint> stops;
final List<RideType> rideTypes;
final RideType? selectedRideType;
final RouteInfo? route;
final FareQuote? quote;
final Trip? trip;
/// موقع السائق الحيّ من `driver:location`.
final GeoPoint? driverLocation;
final List<Place> searchResults;
/// بحث نصّي جارٍ — منفصل عن [busy] كي لا يقفل مؤشّرُ البحثِ الشاشةَ كلها.
final bool searching;
final bool busy;
final RideError error;
final PickTarget pickTarget;
/// وجهة الكاميرا حين يقودها المنطق لا المستخدم.
final GeoPoint? cameraTarget;
/// كود الخصم — يُقيَّم على الخادم عند الطلب لا في التطبيق.
final String couponCode;
bool get canConfirm =>
origin != null &&
destination != null &&
selectedRideType != null &&
quote?.isUsable == true;
RideState copyWith({
RidePhase? phase,
GeoPoint? origin,
GeoPoint? destination,
String? originLabel,
String? destinationLabel,
List<GeoPoint>? stops,
List<RideType>? rideTypes,
RideType? selectedRideType,
RouteInfo? route,
FareQuote? quote,
Trip? trip,
GeoPoint? driverLocation,
List<Place>? searchResults,
bool? searching,
bool? busy,
RideError? error,
PickTarget? pickTarget,
GeoPoint? cameraTarget,
String? couponCode,
bool clearDestination = false,
bool clearRoute = false,
bool clearTrip = false,
bool clearCamera = false,
}) {
return RideState(
phase: phase ?? this.phase,
origin: origin ?? this.origin,
destination: clearDestination ? null : (destination ?? this.destination),
originLabel: originLabel ?? this.originLabel,
destinationLabel: clearDestination
? ''
: (destinationLabel ?? this.destinationLabel),
stops: stops ?? this.stops,
rideTypes: rideTypes ?? this.rideTypes,
selectedRideType: selectedRideType ?? this.selectedRideType,
route: clearRoute ? null : (route ?? this.route),
quote: clearRoute ? null : (quote ?? this.quote),
trip: clearTrip ? null : (trip ?? this.trip),
driverLocation: driverLocation ?? this.driverLocation,
searchResults: searchResults ?? this.searchResults,
searching: searching ?? this.searching,
busy: busy ?? this.busy,
error: error ?? this.error,
pickTarget: pickTarget ?? this.pickTarget,
cameraTarget: clearCamera ? null : (cameraTarget ?? this.cameraTarget),
couponCode: couponCode ?? this.couponCode,
);
}
@override
List<Object?> get props => [
phase,
origin,
destination,
originLabel,
destinationLabel,
stops,
rideTypes,
selectedRideType,
route,
quote,
trip,
driverLocation,
searchResults,
searching,
busy,
error,
pickTarget,
cameraTarget,
couponCode,
];
}