feat: implement core architecture, design system, localization, and trip features for both driver and rider apps.

This commit is contained in:
Hamza-Ayed
2026-07-19 16:21:58 +03:00
parent 959e2fa758
commit c4dfeb4c6f
207 changed files with 14017 additions and 5567 deletions
@@ -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));
}
}