feat: implement core architecture, design system, localization, and trip features for both driver and rider apps.
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import 'dart:async';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../data/maps_repository.dart';
|
||||
import '../data/models/place_model.dart';
|
||||
|
||||
/// حالة شاشة البحث عن الوجهة.
|
||||
class DestinationState extends Equatable {
|
||||
final String query;
|
||||
final List<PlaceModel> results;
|
||||
final bool searching;
|
||||
final String? error;
|
||||
|
||||
const DestinationState({
|
||||
this.query = '',
|
||||
this.results = const [],
|
||||
this.searching = false,
|
||||
this.error,
|
||||
});
|
||||
|
||||
DestinationState copyWith({
|
||||
String? query,
|
||||
List<PlaceModel>? results,
|
||||
bool? searching,
|
||||
String? error,
|
||||
bool clearError = false,
|
||||
}) {
|
||||
return DestinationState(
|
||||
query: query ?? this.query,
|
||||
results: results ?? this.results,
|
||||
searching: searching ?? this.searching,
|
||||
error: clearError ? null : (error ?? this.error),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [query, results, searching, error];
|
||||
}
|
||||
|
||||
/// البحث عن وجهة مع debounce.
|
||||
class DestinationCubit extends Cubit<DestinationState> {
|
||||
final MapsRepository _mapsRepo;
|
||||
Timer? _debounce;
|
||||
|
||||
DestinationCubit(this._mapsRepo) : super(const DestinationState());
|
||||
|
||||
void onQueryChanged(String query) {
|
||||
_debounce?.cancel();
|
||||
emit(state.copyWith(query: query, clearError: true));
|
||||
|
||||
if (query.trim().length < 2) {
|
||||
emit(state.copyWith(results: [], searching: false));
|
||||
return;
|
||||
}
|
||||
|
||||
emit(state.copyWith(searching: true));
|
||||
|
||||
_debounce = Timer(const Duration(milliseconds: 500), () {
|
||||
_search(query);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _search(String query) async {
|
||||
try {
|
||||
final results = await _mapsRepo.autocomplete(query);
|
||||
emit(state.copyWith(results: results, searching: false));
|
||||
} catch (e) {
|
||||
emit(state.copyWith(searching: false, error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> searchDirectly(String query) async {
|
||||
_debounce?.cancel();
|
||||
if (query.trim().length < 2) return;
|
||||
emit(state.copyWith(searching: true, clearError: true));
|
||||
try {
|
||||
final results = await _mapsRepo.autocomplete(query);
|
||||
emit(state.copyWith(results: results, searching: false));
|
||||
} catch (e) {
|
||||
emit(state.copyWith(searching: false, error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_debounce?.cancel();
|
||||
return super.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import 'dart:async';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:intaleq_maps/intaleq_maps.dart';
|
||||
import '../data/maps_repository.dart';
|
||||
import '../data/models/place_model.dart';
|
||||
|
||||
/// حالة شاشة الخريطة الرئيسية.
|
||||
class HomeState extends Equatable {
|
||||
final bool loading;
|
||||
final LatLng? currentLocation;
|
||||
final LatLng? cameraTarget;
|
||||
final PlaceModel? pickup;
|
||||
final PlaceModel? destination;
|
||||
final String? error;
|
||||
|
||||
const HomeState({
|
||||
this.loading = true,
|
||||
this.currentLocation,
|
||||
this.cameraTarget,
|
||||
this.pickup,
|
||||
this.destination,
|
||||
this.error,
|
||||
});
|
||||
|
||||
HomeState copyWith({
|
||||
bool? loading,
|
||||
LatLng? currentLocation,
|
||||
LatLng? cameraTarget,
|
||||
PlaceModel? pickup,
|
||||
PlaceModel? destination,
|
||||
String? error,
|
||||
bool clearPickup = false,
|
||||
bool clearDestination = false,
|
||||
bool clearError = false,
|
||||
}) {
|
||||
return HomeState(
|
||||
loading: loading ?? this.loading,
|
||||
currentLocation: currentLocation ?? this.currentLocation,
|
||||
cameraTarget: cameraTarget ?? this.cameraTarget,
|
||||
pickup: clearPickup ? null : (pickup ?? this.pickup),
|
||||
destination: clearDestination ? null : (destination ?? this.destination),
|
||||
error: clearError ? null : (error ?? this.error),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [loading, currentLocation, cameraTarget, pickup, destination, error];
|
||||
}
|
||||
|
||||
/// إدارة موقع المستخدم الحالي + الخريطة.
|
||||
class HomeCubit extends Cubit<HomeState> {
|
||||
final MapsRepository _mapsRepo;
|
||||
|
||||
HomeCubit(this._mapsRepo) : super(const HomeState()) {
|
||||
initLocation();
|
||||
}
|
||||
|
||||
Future<void> initLocation() async {
|
||||
try {
|
||||
emit(state.copyWith(loading: true, clearError: true));
|
||||
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
if (permission == LocationPermission.denied ||
|
||||
permission == LocationPermission.deniedForever) {
|
||||
emit(state.copyWith(
|
||||
loading: false,
|
||||
error: 'Location permission denied',
|
||||
));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final pos = await Geolocator.getCurrentPosition(
|
||||
locationSettings: const LocationSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
timeLimit: Duration(seconds: 10),
|
||||
),
|
||||
);
|
||||
final loc = LatLng(pos.latitude, pos.longitude);
|
||||
|
||||
// جلب العنوان العكسي للموقع الحالي.
|
||||
final place = await _mapsRepo.reverseGeocode(pos.latitude, pos.longitude);
|
||||
|
||||
emit(state.copyWith(
|
||||
loading: false,
|
||||
currentLocation: loc,
|
||||
cameraTarget: loc,
|
||||
pickup: place,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(state.copyWith(
|
||||
loading: false,
|
||||
error: e.toString(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void updateCameraTarget(LatLng target) {
|
||||
emit(state.copyWith(cameraTarget: target));
|
||||
}
|
||||
|
||||
void setPickup(PlaceModel place) {
|
||||
emit(state.copyWith(pickup: place));
|
||||
}
|
||||
|
||||
void setPickupFromLatLng(LatLng loc, {String? address}) {
|
||||
emit(state.copyWith(
|
||||
pickup: PlaceModel(
|
||||
name: address ?? '',
|
||||
address: address,
|
||||
lat: loc.latitude,
|
||||
lng: loc.longitude,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
void setDestination(PlaceModel place) {
|
||||
emit(state.copyWith(destination: place));
|
||||
}
|
||||
|
||||
void clearTripData() {
|
||||
emit(state.copyWith(clearPickup: true, clearDestination: true, clearError: true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../data/tariff_repository.dart';
|
||||
import '../data/models/quote_model.dart';
|
||||
|
||||
/// حالة شاشة اختيار فئة الرحلة + السعر.
|
||||
class QuoteState extends Equatable {
|
||||
final bool loading;
|
||||
final QuoteModel? quote;
|
||||
final String? selectedClass;
|
||||
final String paymentMethod;
|
||||
final String? couponCode;
|
||||
final String? error;
|
||||
|
||||
const QuoteState({
|
||||
this.loading = false,
|
||||
this.quote,
|
||||
this.selectedClass,
|
||||
this.paymentMethod = 'cash',
|
||||
this.couponCode,
|
||||
this.error,
|
||||
});
|
||||
|
||||
QuoteState copyWith({
|
||||
bool? loading,
|
||||
QuoteModel? quote,
|
||||
String? selectedClass,
|
||||
String? paymentMethod,
|
||||
String? couponCode,
|
||||
String? error,
|
||||
bool clearError = false,
|
||||
bool clearCoupon = false,
|
||||
}) {
|
||||
return QuoteState(
|
||||
loading: loading ?? this.loading,
|
||||
quote: quote ?? this.quote,
|
||||
selectedClass: selectedClass ?? this.selectedClass,
|
||||
paymentMethod: paymentMethod ?? this.paymentMethod,
|
||||
couponCode: clearCoupon ? null : (couponCode ?? this.couponCode),
|
||||
error: clearError ? null : (error ?? this.error),
|
||||
);
|
||||
}
|
||||
|
||||
QuoteClassModel? get selectedQuoteClass {
|
||||
if (quote == null || selectedClass == null) return null;
|
||||
try {
|
||||
return quote!.classes.firstWhere((c) => c.vehicleClass == selectedClass);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [loading, quote, selectedClass, paymentMethod, couponCode, error];
|
||||
}
|
||||
|
||||
/// جلب الأسعار واختيار الفئة.
|
||||
class QuoteCubit extends Cubit<QuoteState> {
|
||||
final TariffRepository _tariffRepo;
|
||||
|
||||
QuoteCubit(this._tariffRepo) : super(const QuoteState());
|
||||
|
||||
Future<void> fetchQuote({
|
||||
required double pickupLat,
|
||||
required double pickupLng,
|
||||
String? pickupAddress,
|
||||
required double dropoffLat,
|
||||
required double dropoffLng,
|
||||
String? dropoffAddress,
|
||||
List<Map<String, dynamic>>? stops,
|
||||
String? vehicleClass,
|
||||
String? scheduledAt,
|
||||
}) async {
|
||||
emit(state.copyWith(loading: true, clearError: true));
|
||||
try {
|
||||
final quote = await _tariffRepo.getQuote(
|
||||
pickupLat: pickupLat,
|
||||
pickupLng: pickupLng,
|
||||
pickupAddress: pickupAddress,
|
||||
dropoffLat: dropoffLat,
|
||||
dropoffLng: dropoffLng,
|
||||
dropoffAddress: dropoffAddress,
|
||||
vehicleClass: vehicleClass,
|
||||
scheduledAt: scheduledAt,
|
||||
);
|
||||
final firstClass = quote.classes.isNotEmpty ? quote.classes.first.vehicleClass : null;
|
||||
emit(state.copyWith(
|
||||
loading: false,
|
||||
quote: quote,
|
||||
selectedClass: firstClass,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(state.copyWith(loading: false, error: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
void selectClass(String vehicleClass) {
|
||||
emit(state.copyWith(selectedClass: vehicleClass));
|
||||
}
|
||||
|
||||
void setPaymentMethod(String method) {
|
||||
emit(state.copyWith(paymentMethod: method));
|
||||
}
|
||||
|
||||
void setCouponCode(String? code) {
|
||||
emit(state.copyWith(couponCode: code));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import '../../../core/api/api_client.dart';
|
||||
import 'models/place_model.dart';
|
||||
import 'models/route_model.dart';
|
||||
|
||||
/// نقطة وصول وحيدة لبيانات الخرائط — كل نداء يمرّ عبر سيرفرنا
|
||||
/// (docs/23 §4) لحماية المفتاح وتفعيل التخزين المؤقت على Redis.
|
||||
class MapsRepository {
|
||||
final ApiClient _api;
|
||||
MapsRepository(this._api);
|
||||
|
||||
/// بحث مكاني — يمرّ عبر `GET /maps/geocode`.
|
||||
Future<List<PlaceModel>> autocomplete(String query) async {
|
||||
if (query.trim().length < 2) return [];
|
||||
final r = await _api.dio.get(
|
||||
'/maps/geocode',
|
||||
queryParameters: {'q': query.trim(), 'country': 'JO'},
|
||||
);
|
||||
final items = (r.data['items'] ?? r.data ?? []) as List;
|
||||
return items
|
||||
.map((e) => PlaceModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// بحث حرّ (geocode).
|
||||
Future<List<PlaceModel>> geocode(String query) async {
|
||||
if (query.trim().length < 2) return [];
|
||||
final r = await _api.dio.get(
|
||||
'/maps/geocode',
|
||||
queryParameters: {'q': query.trim(), 'country': 'JO'},
|
||||
);
|
||||
final items = (r.data['items'] ?? r.data ?? []) as List;
|
||||
return items
|
||||
.map((e) => PlaceModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// تفكيك عنوان عكسي (إحداثيات → نص).
|
||||
Future<PlaceModel> reverseGeocode(double lat, double lng) async {
|
||||
final r = await _api.dio.get(
|
||||
'/maps/reverse',
|
||||
queryParameters: {'lat': lat, 'lng': lng},
|
||||
);
|
||||
final j = r.data as Map<String, dynamic>;
|
||||
return PlaceModel.fromJson({
|
||||
'name': j['formattedAddress'] ?? '',
|
||||
'address': j['formattedAddress'],
|
||||
'lat': lat,
|
||||
'lng': lng,
|
||||
});
|
||||
}
|
||||
|
||||
/// تفاصيل مكان بالـ placeId — يمرّ عبر geocode.
|
||||
Future<PlaceModel> placeDetails(String placeId) async {
|
||||
final r = await _api.dio.get(
|
||||
'/maps/geocode',
|
||||
queryParameters: {'q': placeId, 'country': 'JO'},
|
||||
);
|
||||
final items = (r.data['items'] ?? r.data ?? []) as List;
|
||||
if (items.isEmpty) {
|
||||
throw Exception('Place not found');
|
||||
}
|
||||
return PlaceModel.fromJson(items.first as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
/// حساب المسار بين نقطتين.
|
||||
Future<RouteModel> getRoute({
|
||||
required double fromLat,
|
||||
required double fromLng,
|
||||
required double toLat,
|
||||
required double toLng,
|
||||
}) async {
|
||||
final r = await _api.dio.get(
|
||||
'/maps/route',
|
||||
queryParameters: {
|
||||
'fromLat': fromLat,
|
||||
'fromLng': fromLng,
|
||||
'toLat': toLat,
|
||||
'toLng': toLng,
|
||||
},
|
||||
);
|
||||
return RouteModel.fromJson(r.data as Map<String, dynamic>);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// نموذج مكان من نتائج البحث (autocomplete / geocode).
|
||||
class PlaceModel extends Equatable {
|
||||
final String? placeId;
|
||||
final String name;
|
||||
final String? address;
|
||||
final double lat;
|
||||
final double lng;
|
||||
|
||||
const PlaceModel({
|
||||
this.placeId,
|
||||
required this.name,
|
||||
this.address,
|
||||
required this.lat,
|
||||
required this.lng,
|
||||
});
|
||||
|
||||
factory PlaceModel.fromJson(Map<String, dynamic> j) => PlaceModel(
|
||||
placeId: j['placeId'] as String?,
|
||||
name: (j['description'] ?? j['name'] ?? '') as String,
|
||||
address: j['address'] as String?,
|
||||
lat: (j['lat'] as num).toDouble(),
|
||||
lng: (j['lng'] as num).toDouble(),
|
||||
);
|
||||
|
||||
factory PlaceModel.fromGeocode(Map<String, dynamic> j) => PlaceModel(
|
||||
placeId: j['placeId'] as String?,
|
||||
name: (j['name'] ?? j['formattedAddress'] ?? '') as String,
|
||||
address: j['formattedAddress'] as String?,
|
||||
lat: (j['lat'] as num).toDouble(),
|
||||
lng: (j['lng'] as num).toDouble(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
if (placeId != null) 'placeId': placeId,
|
||||
'name': name,
|
||||
if (address != null) 'address': address,
|
||||
'lat': lat,
|
||||
'lng': lng,
|
||||
};
|
||||
|
||||
@override
|
||||
List<Object?> get props => [placeId, name, address, lat, lng];
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// فئة رحلة واحدة من الاستجابة (tariff/quote).
|
||||
class QuoteClassModel extends Equatable {
|
||||
final String vehicleClass;
|
||||
final String name;
|
||||
final int price;
|
||||
final String currency;
|
||||
final int capacity;
|
||||
final String? description;
|
||||
final String? imageUrl;
|
||||
final int estimatedTime; // ثوانٍ تقريبية
|
||||
|
||||
const QuoteClassModel({
|
||||
required this.vehicleClass,
|
||||
required this.name,
|
||||
required this.price,
|
||||
required this.currency,
|
||||
required this.capacity,
|
||||
this.description,
|
||||
this.imageUrl,
|
||||
required this.estimatedTime,
|
||||
});
|
||||
|
||||
factory QuoteClassModel.fromJson(Map<String, dynamic> j) => QuoteClassModel(
|
||||
vehicleClass: j['vehicleClass'] as String,
|
||||
name: (j['name'] ?? j['vehicleClass']) as String,
|
||||
price: j['price'] as int,
|
||||
currency: (j['currency'] ?? 'JOD') as String,
|
||||
capacity: j['capacity'] as int? ?? 4,
|
||||
description: j['description'] as String?,
|
||||
imageUrl: j['imageUrl'] as String?,
|
||||
estimatedTime: j['estimatedTime'] as int? ?? 0,
|
||||
);
|
||||
|
||||
String get estimatedTimeText {
|
||||
final min = estimatedTime ~/ 60;
|
||||
return '$min min';
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [vehicleClass, name, price, currency, capacity];
|
||||
}
|
||||
|
||||
/// استجابة tariff/quote الكاملة.
|
||||
class QuoteModel extends Equatable {
|
||||
final String? pickupAddress;
|
||||
final String? dropoffAddress;
|
||||
final int distanceMeters;
|
||||
final int durationSeconds;
|
||||
final String? distanceText;
|
||||
final String? durationText;
|
||||
final String currency;
|
||||
final List<QuoteClassModel> classes;
|
||||
|
||||
const QuoteModel({
|
||||
this.pickupAddress,
|
||||
this.dropoffAddress,
|
||||
required this.distanceMeters,
|
||||
required this.durationSeconds,
|
||||
this.distanceText,
|
||||
this.durationText,
|
||||
required this.currency,
|
||||
required this.classes,
|
||||
});
|
||||
|
||||
factory QuoteModel.fromJson(Map<String, dynamic> j) {
|
||||
final data = j['data'] ?? j;
|
||||
return QuoteModel(
|
||||
pickupAddress: data['pickupAddress'] as String?,
|
||||
dropoffAddress: data['dropoffAddress'] as String?,
|
||||
distanceMeters: (data['distanceMeters'] as num?)?.toInt() ?? 0,
|
||||
durationSeconds: (data['durationSeconds'] as num?)?.toInt() ?? 0,
|
||||
distanceText: data['distanceText'] as String?,
|
||||
durationText: data['durationText'] as String?,
|
||||
currency: (data['currency'] ?? 'JOD') as String,
|
||||
classes: (data['classes'] as List? ?? [])
|
||||
.map((c) => QuoteClassModel.fromJson(c as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [distanceMeters, durationSeconds, currency, classes];
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// فئة رحلة من ride-types endpoint (تُستخدم كقائمة المرجع).
|
||||
class RideTypeModel extends Equatable {
|
||||
final String id;
|
||||
final String name;
|
||||
final String? vehicleClass;
|
||||
final int capacity;
|
||||
final String? description;
|
||||
final String? imageUrl;
|
||||
final bool active;
|
||||
|
||||
const RideTypeModel({
|
||||
required this.id,
|
||||
required this.name,
|
||||
this.vehicleClass,
|
||||
required this.capacity,
|
||||
this.description,
|
||||
this.imageUrl,
|
||||
required this.active,
|
||||
});
|
||||
|
||||
factory RideTypeModel.fromJson(Map<String, dynamic> j) => RideTypeModel(
|
||||
id: j['id'] as String,
|
||||
name: (j['name'] ?? '') as String,
|
||||
vehicleClass: j['vehicleClass'] as String?,
|
||||
capacity: j['capacity'] as int? ?? 4,
|
||||
description: j['description'] as String?,
|
||||
imageUrl: j['imageUrl'] as String?,
|
||||
active: j['active'] as bool? ?? true,
|
||||
);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, name, vehicleClass, capacity, active];
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:intaleq_maps/intaleq_maps.dart';
|
||||
|
||||
/// خطاب polyline مشفر ومسافة/وقت تقريبيان.
|
||||
class RouteModel extends Equatable {
|
||||
final int distanceMeters;
|
||||
final int durationSeconds;
|
||||
final String? polyline;
|
||||
|
||||
const RouteModel({
|
||||
required this.distanceMeters,
|
||||
required this.durationSeconds,
|
||||
this.polyline,
|
||||
});
|
||||
|
||||
factory RouteModel.fromJson(Map<String, dynamic> j) {
|
||||
final dist = j['distanceMeters'] ?? j['distance'];
|
||||
final dur = j['durationSeconds'] ?? j['duration'];
|
||||
return RouteModel(
|
||||
distanceMeters: dist is int ? dist : int.tryParse('$dist') ?? 0,
|
||||
durationSeconds: dur is int ? dur : int.tryParse('$dur') ?? 0,
|
||||
polyline: j['polyline'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
String get distanceText {
|
||||
if (distanceMeters < 1000) return '$distanceMeters m';
|
||||
return '${(distanceMeters / 1000).toStringAsFixed(1)} km';
|
||||
}
|
||||
|
||||
String get durationText {
|
||||
final min = durationSeconds ~/ 60;
|
||||
if (min < 60) return '$min min';
|
||||
final h = min ~/ 60;
|
||||
final rem = min % 60;
|
||||
return '$h h ${rem > 0 ? '$rem min' : ''}';
|
||||
}
|
||||
|
||||
List<LatLng> decodePolyline() {
|
||||
if (polyline == null || polyline!.isEmpty) return [];
|
||||
return _decodeEncodedPolyline(polyline!);
|
||||
}
|
||||
|
||||
/// فك تشفير polyline وفقاً لخوارزمية Google.
|
||||
static List<LatLng> _decodeEncodedPolyline(String encoded) {
|
||||
final List<LatLng> poly = [];
|
||||
int index = 0, lat = 0, lng = 0;
|
||||
|
||||
while (index < encoded.length) {
|
||||
int b, shift = 0, result = 0;
|
||||
do {
|
||||
b = encoded.codeUnitAt(index++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
lat += ((result & 1) != 0) ? ~(result >> 1) : (result >> 1);
|
||||
|
||||
shift = 0;
|
||||
result = 0;
|
||||
do {
|
||||
b = encoded.codeUnitAt(index++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
lng += ((result & 1) != 0) ? ~(result >> 1) : (result >> 1);
|
||||
|
||||
poly.add(LatLng(lat / 1e5, lng / 1e5));
|
||||
}
|
||||
return poly;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [distanceMeters, durationSeconds, polyline];
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
/// نقطة توقف أثناء الرحلة.
|
||||
class StopModel extends Equatable {
|
||||
final double lat;
|
||||
final double lng;
|
||||
final String? label;
|
||||
final String? address;
|
||||
|
||||
const StopModel({
|
||||
required this.lat,
|
||||
required this.lng,
|
||||
this.label,
|
||||
this.address,
|
||||
});
|
||||
|
||||
factory StopModel.fromJson(Map<String, dynamic> j) => StopModel(
|
||||
lat: (j['lat'] as num).toDouble(),
|
||||
lng: (j['lng'] as num).toDouble(),
|
||||
label: j['label'] as String?,
|
||||
address: j['address'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'lat': lat,
|
||||
'lng': lng,
|
||||
if (label != null) 'label': label,
|
||||
if (address != null) 'address': address,
|
||||
};
|
||||
|
||||
@override
|
||||
List<Object?> get props => [lat, lng, label, address];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import '../../../core/api/api_client.dart';
|
||||
import 'models/ride_type_model.dart';
|
||||
|
||||
/// جلب فئات الرحلة المتاحة من المستأجر.
|
||||
class RideTypesRepository {
|
||||
final ApiClient _api;
|
||||
RideTypesRepository(this._api);
|
||||
|
||||
/// GET /ride-types — تُستخدم كمرجع للفئات النشطة.
|
||||
Future<List<RideTypeModel>> getRideTypes() async {
|
||||
final r = await _api.dio.get('/ride-types');
|
||||
final items = (r.data['items'] ?? r.data ?? []) as List;
|
||||
return items
|
||||
.map((e) => RideTypeModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import '../../../core/api/api_client.dart';
|
||||
import 'models/quote_model.dart';
|
||||
import 'models/stop_model.dart';
|
||||
|
||||
/// استخراج الأسعار لكل فئة رحلة.
|
||||
class TariffRepository {
|
||||
final ApiClient _api;
|
||||
TariffRepository(this._api);
|
||||
|
||||
/// جلب عرض أسعار للمسار المحدد — POST /tariff/quote.
|
||||
///
|
||||
/// الاستجابة تحتوي `classes[]` بسعر لكل فئة مع breakdown.
|
||||
Future<QuoteModel> getQuote({
|
||||
required double pickupLat,
|
||||
required double pickupLng,
|
||||
required String? pickupAddress,
|
||||
required double dropoffLat,
|
||||
required double dropoffLng,
|
||||
required String? dropoffAddress,
|
||||
List<StopModel>? stops,
|
||||
String? vehicleClass,
|
||||
String? scheduledAt,
|
||||
}) async {
|
||||
final data = <String, dynamic>{
|
||||
'pickup': {
|
||||
'lat': pickupLat,
|
||||
'lng': pickupLng,
|
||||
if (pickupAddress != null) 'address': pickupAddress,
|
||||
},
|
||||
'dropoff': {
|
||||
'lat': dropoffLat,
|
||||
'lng': dropoffLng,
|
||||
if (dropoffAddress != null) 'address': dropoffAddress,
|
||||
},
|
||||
};
|
||||
if (stops != null && stops.isNotEmpty) {
|
||||
data['stops'] = stops.nonNulls.map((s) => s.toJson()).toList();
|
||||
}
|
||||
if (vehicleClass != null) data['vehicleClass'] = vehicleClass;
|
||||
if (scheduledAt != null) data['scheduledAt'] = scheduledAt;
|
||||
|
||||
final r = await _api.dio.post('/tariff/quote', data: data);
|
||||
return QuoteModel.fromJson(r.data as Map<String, dynamic>);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../core/l10n/app_localizations.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../core/design/tokens.dart';
|
||||
import '../../../core/ui/tripz_scaffold.dart';
|
||||
import '../../../core/ui/tripz_text_field.dart';
|
||||
import '../cubit/destination_cubit.dart';
|
||||
import '../data/models/place_model.dart';
|
||||
import 'widgets/place_tile.dart';
|
||||
|
||||
/// شاشة البحث عن وجهة — full-screen مع autocomplete.
|
||||
class DestinationScreen extends StatefulWidget {
|
||||
const DestinationScreen({super.key});
|
||||
|
||||
@override
|
||||
State<DestinationScreen> createState() => _DestinationScreenState();
|
||||
}
|
||||
|
||||
class _DestinationScreenState extends State<DestinationScreen> {
|
||||
final _controller = TextEditingController();
|
||||
final _focusNode = FocusNode();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_focusNode.requestFocus();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
_focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
return TripzScaffold(
|
||||
padding: false,
|
||||
child: Column(
|
||||
children: [
|
||||
_SearchHeader(
|
||||
controller: _controller,
|
||||
focusNode: _focusNode,
|
||||
l10n: l10n,
|
||||
),
|
||||
Expanded(
|
||||
child: BlocBuilder<DestinationCubit, DestinationState>(
|
||||
builder: (context, state) {
|
||||
if (state.searching) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (state.results.isEmpty && state.query.length >= 2) {
|
||||
return Center(
|
||||
child: Text(l10n.noResults, style: Theme.of(context).textTheme.bodyLarge),
|
||||
);
|
||||
}
|
||||
return ListView.builder(
|
||||
padding: EdgeInsets.zero,
|
||||
itemCount: state.results.length,
|
||||
itemBuilder: (context, index) {
|
||||
final place = state.results[index];
|
||||
return PlaceTile(
|
||||
place: place,
|
||||
onTap: () => context.pop<PlaceModel>(place),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(T.pagePadding),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => context.pop<PlaceModel>(null),
|
||||
icon: const Icon(Icons.map_outlined),
|
||||
label: Text(l10n.chooseOnMap),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SearchHeader extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
final FocusNode focusNode;
|
||||
final AppLocalizations l10n;
|
||||
|
||||
const _SearchHeader({
|
||||
required this.controller,
|
||||
required this.focusNode,
|
||||
required this.l10n,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
return Container(
|
||||
color: cs.surface,
|
||||
padding: const EdgeInsets.only(
|
||||
left: T.pagePadding,
|
||||
right: T.pagePadding,
|
||||
top: T.s8,
|
||||
bottom: T.s12,
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
icon: const Icon(Icons.arrow_back_rounded),
|
||||
),
|
||||
Expanded(
|
||||
child: TripzTextField(
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
hint: l10n.searchPlaces,
|
||||
prefix: const Icon(Icons.search_rounded),
|
||||
onChanged: (v) => context.read<DestinationCubit>().onQueryChanged(v),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: T.s8),
|
||||
Row(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: BoxDecoration(
|
||||
color: cs.primary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
Container(width: 1.5, height: 24, color: cs.outlineVariant),
|
||||
Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: BoxDecoration(
|
||||
color: cs.error,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: T.s12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
l10n.pickupLocation,
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: cs.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: T.s4),
|
||||
Text(
|
||||
l10n.pickupSet,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: T.s16),
|
||||
Text(
|
||||
l10n.dropoffLocation,
|
||||
style: Theme.of(context).textTheme.labelSmall?.copyWith(
|
||||
color: cs.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,76 +1,260 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import '../../../core/l10n/app_localizations.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intaleq_maps/intaleq_maps.dart';
|
||||
import '../../auth/cubit/auth_cubit.dart';
|
||||
import '../../auth/cubit/auth_state.dart';
|
||||
import '../../../core/ui/tripz_button.dart';
|
||||
import '../../../core/design/tokens.dart';
|
||||
import '../../trip/bloc/trip_bloc.dart';
|
||||
import '../../trip/bloc/trip_state.dart';
|
||||
import '../../trip/bloc/trip_event.dart';
|
||||
import '../cubit/home_cubit.dart';
|
||||
import '../data/models/place_model.dart';
|
||||
|
||||
class HomeScreen extends StatelessWidget {
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({super.key});
|
||||
|
||||
@override
|
||||
State<HomeScreen> createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
IntaleqMapController? _mapController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// فحص رحلة نشطة عند فتح الشاشة.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.read<TripBloc>().add(const TripCheckActive());
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final center = const LatLng(31.9539, 35.9106); // عمّان
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Tripz'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.logout),
|
||||
onPressed: () => context.read<AuthCubit>().logout(),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
FlutterMap(
|
||||
options: MapOptions(initialCenter: center, initialZoom: 13),
|
||||
children: [
|
||||
// TODO: استبدال بلاطات انطلق (Martin) بدل OSM
|
||||
TileLayer(
|
||||
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
userAgentPackageName: 'com.mobileapp.store.ride',
|
||||
),
|
||||
MarkerLayer(markers: [
|
||||
Marker(
|
||||
point: center,
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: const Icon(Icons.location_pin, color: Colors.red, size: 40),
|
||||
),
|
||||
]),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
left: 16,
|
||||
right: 16,
|
||||
bottom: 24,
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: BlocBuilder<AuthCubit, AuthState>(
|
||||
builder: (context, state) {
|
||||
final name = state.user?.name ?? state.user?.phone ?? '';
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('مرحباً $name',
|
||||
style: Theme.of(context).textTheme.titleMedium),
|
||||
const SizedBox(height: 12),
|
||||
FilledButton.icon(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.local_taxi),
|
||||
label: const Text('اطلب رحلة (قريباً)'),
|
||||
),
|
||||
],
|
||||
);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return BlocListener<TripBloc, TripState>(
|
||||
listenWhen: (prev, cur) => prev.trip?.status != cur.trip?.status,
|
||||
listener: (context, state) {
|
||||
if (state.trip != null && !state.isCompleted) {
|
||||
// رحلة نشطة — انتقل للتتبع.
|
||||
context.push('/trip-tracking');
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
// الخريطة
|
||||
BlocBuilder<HomeCubit, HomeState>(
|
||||
builder: (context, state) {
|
||||
final center = state.currentLocation ?? const LatLng(31.9539, 35.9106);
|
||||
return IntaleqMap(
|
||||
apiKey: '',
|
||||
initialCameraPosition: CameraPosition(target: center, zoom: 15),
|
||||
myLocationEnabled: true,
|
||||
zoomControlsEnabled: false,
|
||||
compassEnabled: false,
|
||||
onMapCreated: (controller) => _mapController = controller,
|
||||
markers: _buildMarkers(state),
|
||||
onCameraMove: (position) {
|
||||
context.read<HomeCubit>().updateCameraTarget(position.target);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
// زر إعادة التوسيط
|
||||
Positioned(
|
||||
right: T.pagePadding,
|
||||
bottom: 180,
|
||||
child: FloatingActionButton.small(
|
||||
heroTag: 'recenter',
|
||||
backgroundColor: cs.surface,
|
||||
onPressed: () {
|
||||
final loc = context.read<HomeCubit>().state.currentLocation;
|
||||
if (loc != null) {
|
||||
_mapController?.animateCamera(CameraUpdate.newLatLngZoom(loc, 15));
|
||||
}
|
||||
},
|
||||
child: Icon(Icons.my_location_rounded, color: cs.onSurface),
|
||||
),
|
||||
),
|
||||
|
||||
// الشريط السفلي
|
||||
Positioned(
|
||||
left: T.pagePadding,
|
||||
right: T.pagePadding,
|
||||
bottom: T.pagePadding,
|
||||
child: Card(
|
||||
elevation: 2,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(T.pagePadding),
|
||||
child: BlocBuilder<HomeCubit, HomeState>(
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
BlocBuilder<AuthCubit, AuthState>(
|
||||
builder: (context, authState) {
|
||||
final name = authState.user?.name ?? '';
|
||||
if (name.isNotEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: T.s12),
|
||||
child: Text(
|
||||
l10n.welcome(name),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
if (state.destination != null)
|
||||
_DestinationPreview(
|
||||
destination: state.destination!,
|
||||
onTap: () => _openDestinationSearch(context),
|
||||
onClear: () => context.read<HomeCubit>().clearTripData(),
|
||||
)
|
||||
else
|
||||
TripzButton(
|
||||
label: l10n.whereTo,
|
||||
style: TripzButtonStyle.secondary,
|
||||
icon: Icons.search_rounded,
|
||||
onPressed: () => _openDestinationSearch(context),
|
||||
),
|
||||
if (state.destination != null) ...[
|
||||
const SizedBox(height: T.s12),
|
||||
TripzButton(
|
||||
label: l10n.requestRide,
|
||||
onPressed: () => _openRoutePreview(context, state),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// حالة التحميل
|
||||
BlocBuilder<HomeCubit, HomeState>(
|
||||
builder: (context, state) {
|
||||
if (state.loading) {
|
||||
return Container(
|
||||
color: Colors.black26,
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Set<Marker> _buildMarkers(HomeState state) {
|
||||
final markers = <Marker>{};
|
||||
if (state.pickup != null) {
|
||||
markers.add(Marker(
|
||||
markerId: const MarkerId('pickup'),
|
||||
position: LatLng(state.pickup!.lat, state.pickup!.lng),
|
||||
icon: InlqBitmap.defaultMarkerWithHue(210),
|
||||
anchor: const Offset(0.5, 1.0),
|
||||
zIndex: 2,
|
||||
));
|
||||
}
|
||||
if (state.destination != null) {
|
||||
markers.add(Marker(
|
||||
markerId: const MarkerId('destination'),
|
||||
position: LatLng(state.destination!.lat, state.destination!.lng),
|
||||
icon: InlqBitmap.defaultMarkerWithHue(0),
|
||||
anchor: const Offset(0.5, 1.0),
|
||||
zIndex: 1,
|
||||
));
|
||||
}
|
||||
return markers;
|
||||
}
|
||||
|
||||
void _openDestinationSearch(BuildContext context) {
|
||||
context.push<PlaceModel>('/destination').then((place) {
|
||||
if (place != null && mounted) {
|
||||
context.read<HomeCubit>().setDestination(place);
|
||||
_openRoutePreview(context, context.read<HomeCubit>().state);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _openRoutePreview(BuildContext context, HomeState state) {
|
||||
if (state.pickup == null || state.destination == null) return;
|
||||
context.push('/route-preview', extra: {
|
||||
'pickup': state.pickup,
|
||||
'destination': state.destination,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class _DestinationPreview extends StatelessWidget {
|
||||
final PlaceModel destination;
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback onClear;
|
||||
|
||||
const _DestinationPreview({
|
||||
required this.destination,
|
||||
required this.onTap,
|
||||
required this.onClear,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(T.s12),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.location_on_outlined, color: cs.error, size: 20),
|
||||
const SizedBox(width: T.s8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
destination.name,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.w500),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
if (destination.address != null)
|
||||
Text(
|
||||
destination.address!,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(color: cs.onSurfaceVariant),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: onClear,
|
||||
icon: Icon(Icons.close_rounded, color: cs.onSurfaceVariant, size: 20),
|
||||
visualDensity: VisualDensity.compact,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,307 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../core/l10n/app_localizations.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intaleq_maps/intaleq_maps.dart';
|
||||
import '../../../core/design/tokens.dart';
|
||||
import '../../../core/ui/tripz_button.dart';
|
||||
import '../../trip/bloc/trip_bloc.dart';
|
||||
import '../../trip/bloc/trip_state.dart';
|
||||
import '../../trip/bloc/trip_event.dart';
|
||||
import '../cubit/quote_cubit.dart';
|
||||
import '../data/models/place_model.dart';
|
||||
import 'widgets/ride_class_card.dart';
|
||||
|
||||
/// شاشة معاينة المسار + اختيار فئة الرحلة + تأكيد الطلب.
|
||||
class RoutePreviewScreen extends StatefulWidget {
|
||||
final PlaceModel pickup;
|
||||
final PlaceModel destination;
|
||||
|
||||
const RoutePreviewScreen({
|
||||
super.key,
|
||||
required this.pickup,
|
||||
required this.destination,
|
||||
});
|
||||
|
||||
@override
|
||||
State<RoutePreviewScreen> createState() => _RoutePreviewScreenState();
|
||||
}
|
||||
|
||||
class _RoutePreviewScreenState extends State<RoutePreviewScreen> {
|
||||
IntaleqMapController? _mapController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.read<QuoteCubit>().fetchQuote(
|
||||
pickupLat: widget.pickup.lat,
|
||||
pickupLng: widget.pickup.lng,
|
||||
pickupAddress: widget.pickup.name,
|
||||
dropoffLat: widget.destination.lat,
|
||||
dropoffLng: widget.destination.lng,
|
||||
dropoffAddress: widget.destination.name,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
final pickupLoc = LatLng(widget.pickup.lat, widget.pickup.lng);
|
||||
final destLoc = LatLng(widget.destination.lat, widget.destination.lng);
|
||||
|
||||
return BlocListener<TripBloc, TripState>(
|
||||
listenWhen: (prev, cur) =>
|
||||
prev.requestStatus != cur.requestStatus &&
|
||||
cur.requestStatus == TripRequestStatus.searching,
|
||||
listener: (context, state) {
|
||||
// تم إنشاء الرحلة — انتقل للتتبع.
|
||||
context.pushReplacement('/trip-tracking');
|
||||
},
|
||||
child: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
// الخريطة مع المسار
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Stack(
|
||||
children: [
|
||||
IntaleqMap(
|
||||
apiKey: '',
|
||||
initialCameraPosition: CameraPosition(
|
||||
target: LatLng(
|
||||
(pickupLoc.latitude + destLoc.latitude) / 2,
|
||||
(pickupLoc.longitude + destLoc.longitude) / 2,
|
||||
),
|
||||
zoom: 14,
|
||||
),
|
||||
myLocationEnabled: false,
|
||||
zoomControlsEnabled: false,
|
||||
compassEnabled: false,
|
||||
onMapCreated: (c) => _mapController = c,
|
||||
markers: {
|
||||
Marker(
|
||||
markerId: const MarkerId('pickup'),
|
||||
position: pickupLoc,
|
||||
icon: InlqBitmap.defaultMarkerWithHue(210),
|
||||
anchor: const Offset(0.5, 1.0),
|
||||
),
|
||||
Marker(
|
||||
markerId: const MarkerId('destination'),
|
||||
position: destLoc,
|
||||
icon: InlqBitmap.defaultMarkerWithHue(0),
|
||||
anchor: const Offset(0.5, 1.0),
|
||||
),
|
||||
},
|
||||
polylines: {
|
||||
Polyline(
|
||||
polylineId: const PolylineId('route'),
|
||||
points: [pickupLoc, destLoc],
|
||||
color: cs.primary,
|
||||
width: 4,
|
||||
),
|
||||
},
|
||||
),
|
||||
Positioned(
|
||||
top: MediaQuery.of(context).padding.top + T.s8,
|
||||
left: T.s12,
|
||||
child: FloatingActionButton.small(
|
||||
heroTag: 'back',
|
||||
backgroundColor: cs.surface,
|
||||
onPressed: () => context.pop(),
|
||||
child: const Icon(Icons.arrow_back_rounded),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: MediaQuery.of(context).padding.top + T.s8,
|
||||
right: T.s12,
|
||||
child: BlocBuilder<QuoteCubit, QuoteState>(
|
||||
builder: (context, state) {
|
||||
if (state.quote == null) return const SizedBox.shrink();
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: T.s12, vertical: T.s8),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surface,
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
boxShadow: [T.shadowSm],
|
||||
),
|
||||
child: Text(
|
||||
l10n.routeSummary(
|
||||
state.quote!.distanceText ?? '',
|
||||
state.quote!.durationText ?? '',
|
||||
),
|
||||
style: Theme.of(context).textTheme.labelLarge,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// قائمة فئات الرحلة
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Container(
|
||||
color: cs.surface,
|
||||
child: BlocBuilder<QuoteCubit, QuoteState>(
|
||||
builder: (context, state) {
|
||||
if (state.loading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (state.error != null) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(l10n.errorGeneric),
|
||||
const SizedBox(height: T.s12),
|
||||
TripzButton(
|
||||
label: l10n.retry,
|
||||
onPressed: () => context.read<QuoteCubit>().fetchQuote(
|
||||
pickupLat: widget.pickup.lat,
|
||||
pickupLng: widget.pickup.lng,
|
||||
pickupAddress: widget.pickup.name,
|
||||
dropoffLat: widget.destination.lat,
|
||||
dropoffLng: widget.destination.lng,
|
||||
dropoffAddress: widget.destination.name,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final classes = state.quote?.classes ?? [];
|
||||
if (classes.isEmpty) {
|
||||
return Center(child: Text(l10n.noResults));
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(T.pagePadding, T.s16, T.pagePadding, T.s8),
|
||||
child: Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Text(l10n.rideClasses, style: Theme.of(context).textTheme.titleMedium),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
padding: const EdgeInsets.symmetric(horizontal: T.pagePadding),
|
||||
itemCount: classes.length,
|
||||
separatorBuilder: (_, __) => const SizedBox(height: T.s8),
|
||||
itemBuilder: (context, index) {
|
||||
final cls = classes[index];
|
||||
return RideClassCard(
|
||||
quoteClass: cls,
|
||||
selected: state.selectedClass == cls.vehicleClass,
|
||||
onTap: () => context.read<QuoteCubit>().selectClass(cls.vehicleClass),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(T.pagePadding),
|
||||
child: Column(
|
||||
children: [
|
||||
_PaymentRow(
|
||||
method: state.paymentMethod,
|
||||
onChanged: (m) => context.read<QuoteCubit>().setPaymentMethod(m),
|
||||
),
|
||||
const SizedBox(height: T.s12),
|
||||
// زر طلب الرحلة — يستخدم TripBloc
|
||||
BlocBuilder<TripBloc, TripState>(
|
||||
builder: (context, tripState) {
|
||||
final isLoading = tripState.requestStatus == TripRequestStatus.loading;
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: TripzButton(
|
||||
label: isLoading ? l10n.loading : l10n.requestRide,
|
||||
onPressed: (state.selectedClass != null && !isLoading)
|
||||
? () => _requestTrip(context, state)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _requestTrip(BuildContext context, QuoteState state) {
|
||||
if (state.selectedClass == null) return;
|
||||
context.read<TripBloc>().add(TripRequested(
|
||||
pickupLat: widget.pickup.lat,
|
||||
pickupLng: widget.pickup.lng,
|
||||
pickupAddress: widget.pickup.name,
|
||||
dropoffLat: widget.destination.lat,
|
||||
dropoffLng: widget.destination.lng,
|
||||
dropoffAddress: widget.destination.name,
|
||||
vehicleClass: state.selectedClass!,
|
||||
paymentMethod: state.paymentMethod,
|
||||
couponCode: state.couponCode,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
class _PaymentRow extends StatelessWidget {
|
||||
final String method;
|
||||
final ValueChanged<String> onChanged;
|
||||
|
||||
const _PaymentRow({required this.method, required this.onChanged});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: T.pagePadding, vertical: T.s12),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
method == 'wallet' ? Icons.account_balance_wallet_outlined : Icons.money_rounded,
|
||||
color: cs.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: T.s12),
|
||||
Text(l10n.paymentMethod, style: Theme.of(context).textTheme.bodyMedium),
|
||||
const Spacer(),
|
||||
DropdownButton<String>(
|
||||
value: method,
|
||||
underline: const SizedBox.shrink(),
|
||||
isDense: true,
|
||||
items: [
|
||||
DropdownMenuItem(value: 'cash', child: Text(l10n.cash)),
|
||||
DropdownMenuItem(value: 'wallet', child: Text(l10n.walletPayment)),
|
||||
],
|
||||
onChanged: (v) {
|
||||
if (v != null) onChanged(v);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../core/design/tokens.dart';
|
||||
import '../../data/models/place_model.dart';
|
||||
|
||||
/// عنصر نتائج البحث عن مكان.
|
||||
class PlaceTile extends StatelessWidget {
|
||||
final PlaceModel place;
|
||||
final VoidCallback? onTap;
|
||||
final IconData? icon;
|
||||
|
||||
const PlaceTile({
|
||||
super.key,
|
||||
required this.place,
|
||||
this.onTap,
|
||||
this.icon,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
final displayIcon = icon ?? Icons.location_on_outlined;
|
||||
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: T.pagePadding,
|
||||
vertical: T.s12,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surfaceContainerHighest,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(displayIcon, size: 20, color: cs.onSurfaceVariant),
|
||||
),
|
||||
const SizedBox(width: T.s12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
place.name,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
if (place.address != null && place.address!.isNotEmpty) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
place.address!,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: cs.onSurfaceVariant,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
Icon(Icons.chevron_right_rounded, color: cs.onSurfaceVariant),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../core/l10n/app_localizations.dart';
|
||||
import '../../../../core/design/tokens.dart';
|
||||
import '../../data/models/quote_model.dart';
|
||||
|
||||
/// بطاقة فئة رحلة واحدة في قائمة الاختيار.
|
||||
class RideClassCard extends StatelessWidget {
|
||||
final QuoteClassModel quoteClass;
|
||||
final bool selected;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const RideClassCard({
|
||||
super.key,
|
||||
required this.quoteClass,
|
||||
this.selected = false,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(T.pagePadding),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? cs.primaryContainer : cs.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
border: Border.all(
|
||||
color: selected ? cs.primary : Colors.transparent,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
// أيقونة المركبة
|
||||
Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? cs.primary : cs.surface,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.directions_car_filled_rounded,
|
||||
color: selected ? cs.onPrimary : cs.onSurfaceVariant,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: T.s12),
|
||||
|
||||
// اسم الفئة + السعة
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
quoteClass.name,
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
l10n.capacity(quoteClass.capacity),
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: cs.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// الوقت التقديري + السعر
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
quoteClass.estimatedTimeText,
|
||||
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||
color: cs.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'${quoteClass.price} ${quoteClass.currency}',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w700,
|
||||
color: selected ? cs.primary : cs.onSurface,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../core/l10n/app_localizations.dart';
|
||||
import '../../../../core/design/tokens.dart';
|
||||
|
||||
/// طبقة البحث عن سائق — نبض + مؤقت + زر إلغاء.
|
||||
class SearchingOverlay extends StatefulWidget {
|
||||
final int elapsed;
|
||||
final VoidCallback? onCancel;
|
||||
|
||||
const SearchingOverlay({
|
||||
super.key,
|
||||
required this.elapsed,
|
||||
this.onCancel,
|
||||
});
|
||||
|
||||
@override
|
||||
State<SearchingOverlay> createState() => _SearchingOverlayState();
|
||||
}
|
||||
|
||||
class _SearchingOverlayState extends State<SearchingOverlay>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _pulseController;
|
||||
late Animation<double> _pulseAnimation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_pulseController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(seconds: 2),
|
||||
)..repeat(reverse: true);
|
||||
_pulseAnimation = Tween<double>(begin: 0.8, end: 1.2).animate(
|
||||
CurvedAnimation(parent: _pulseController, curve: Curves.easeInOut),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pulseController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
final minutes = widget.elapsed ~/ 60;
|
||||
final seconds = widget.elapsed % 60;
|
||||
final timeStr = '${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}';
|
||||
|
||||
return Material(
|
||||
color: Colors.black54,
|
||||
child: Center(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(T.pagePadding * 2),
|
||||
padding: const EdgeInsets.all(T.pagePadding * 1.5),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surface,
|
||||
borderRadius: BorderRadius.circular(T.r16),
|
||||
boxShadow: [T.shadowLg],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// نبض البحث
|
||||
ScaleTransition(
|
||||
scale: _pulseAnimation,
|
||||
child: Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: cs.primaryContainer,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.directions_car_filled_rounded,
|
||||
size: 40,
|
||||
color: cs.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: T.s16),
|
||||
|
||||
// نص البحث
|
||||
Text(
|
||||
l10n.searchingDriver,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
|
||||
const SizedBox(height: T.s8),
|
||||
|
||||
// المؤقت
|
||||
Text(
|
||||
timeStr,
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
color: cs.primary,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontFeatures: const [FontFeature.tabularFigures()],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: T.s20),
|
||||
|
||||
// زر الإلغاء
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton(
|
||||
onPressed: widget.onCancel,
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: cs.error,
|
||||
side: BorderSide(color: cs.error),
|
||||
),
|
||||
child: Text(l10n.cancelSearch),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user