261 lines
8.7 KiB
Dart
261 lines
8.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:driver/core/l10n/app_localizations.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:intaleq_maps/intaleq_maps.dart';
|
|
import '../../../core/design/tokens.dart';
|
|
import '../../trip/bloc/driver_trip_bloc.dart';
|
|
import 'widgets/trip_action_button.dart';
|
|
|
|
/// شاشة تنفيذ الرحلة — تتبع السائق أثناء تنفيذ الرحلة.
|
|
///
|
|
/// الحالات:
|
|
/// - `assigned`: عرض pickup + زر "في الطريق"
|
|
/// - `driver_arriving`: تتبع المسار إلى العميل
|
|
/// - `driver_arrived`: انتظار العميل + زر "بدء الرحلة"
|
|
/// - `in_progress`: تتبع المسار إلى dropoff + زر "إتمام"
|
|
class DriverTripScreen extends StatelessWidget {
|
|
const DriverTripScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context)!;
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
return BlocBuilder<DriverTripBloc, DriverTripState>(
|
|
builder: (context, state) {
|
|
if (state.trip == null) {
|
|
return const Scaffold(
|
|
body: Center(child: CircularProgressIndicator()),
|
|
);
|
|
}
|
|
|
|
final trip = state.trip!;
|
|
final statusLabel = _statusLabel(l10n, trip.status);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(statusLabel),
|
|
centerTitle: true,
|
|
automaticallyImplyLeading: false,
|
|
actions: [
|
|
if (state.canCancel)
|
|
TextButton(
|
|
onPressed: () => _showCancelDialog(context, l10n),
|
|
child: Text(
|
|
l10n.cancel,
|
|
style: TextStyle(color: cs.error),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
body: Column(
|
|
children: [
|
|
// ── الخريطة ──
|
|
Expanded(
|
|
flex: 3,
|
|
child: _buildMap(context, trip),
|
|
),
|
|
|
|
// ── معلومات + زر ──
|
|
Expanded(
|
|
flex: 2,
|
|
child: Container(
|
|
padding: const EdgeInsets.all(T.s16),
|
|
decoration: BoxDecoration(
|
|
color: cs.surface,
|
|
borderRadius: const BorderRadius.vertical(
|
|
top: Radius.circular(T.r24),
|
|
),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withValues(alpha: 0.08),
|
|
blurRadius: 12,
|
|
offset: const Offset(0, -4),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// معلومات العميل
|
|
if (trip.clientName != null)
|
|
Row(
|
|
children: [
|
|
CircleAvatar(
|
|
radius: 20,
|
|
backgroundColor: cs.primaryContainer,
|
|
child: Icon(Icons.person, color: cs.onPrimaryContainer),
|
|
),
|
|
const SizedBox(width: T.s12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
trip.clientName!,
|
|
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
if (trip.clientPhone != null)
|
|
Text(
|
|
trip.clientPhone!,
|
|
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: cs.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
const SizedBox(height: T.s12),
|
|
|
|
// نقاط pickup/dropoff
|
|
_InfoRow(
|
|
dotColor: const Color(0xFF4CAF50),
|
|
label: trip.pickupAddress ?? l10n.pickupLocation,
|
|
),
|
|
const SizedBox(height: T.s4),
|
|
_InfoRow(
|
|
dotColor: const Color(0xFFF44336),
|
|
label: trip.dropoffAddress ?? l10n.dropoffLocation,
|
|
),
|
|
|
|
if (trip.fare != null) ...[
|
|
const SizedBox(height: T.s8),
|
|
Text(
|
|
'${l10n.tripFare}: ${trip.fare} ${trip.currency ?? ""}',
|
|
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
|
fontWeight: FontWeight.w600,
|
|
color: cs.primary,
|
|
),
|
|
),
|
|
],
|
|
|
|
const Spacer(),
|
|
|
|
// زر الإجراء التالي
|
|
TripActionButton(trip: trip),
|
|
|
|
if (state.error != null) ...[
|
|
const SizedBox(height: T.s8),
|
|
Text(
|
|
state.error!,
|
|
style: TextStyle(color: cs.error, fontSize: 12),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _buildMap(BuildContext context, dynamic trip) {
|
|
return IntaleqMap(
|
|
apiKey: '',
|
|
initialCameraPosition: CameraPosition(
|
|
target: LatLng(trip.pickupLat, trip.pickupLng),
|
|
zoom: 14,
|
|
),
|
|
myLocationEnabled: true,
|
|
myLocationButtonEnabled: false,
|
|
zoomControlsEnabled: false,
|
|
markers: {
|
|
Marker(
|
|
markerId: const MarkerId('pickup'),
|
|
position: LatLng(trip.pickupLat, trip.pickupLng),
|
|
infoWindow: InfoWindow(title: AppLocalizations.of(context)!.pickupLocation),
|
|
),
|
|
if (trip.dropoffLat != 0 && trip.dropoffLng != 0)
|
|
Marker(
|
|
markerId: const MarkerId('dropoff'),
|
|
position: LatLng(trip.dropoffLat, trip.dropoffLng),
|
|
infoWindow: InfoWindow(title: AppLocalizations.of(context)!.dropoffLocation),
|
|
),
|
|
},
|
|
);
|
|
}
|
|
|
|
String _statusLabel(AppLocalizations l10n, String status) {
|
|
switch (status) {
|
|
case 'assigned':
|
|
return l10n.tripAssigned;
|
|
case 'driver_arriving':
|
|
return l10n.onTheWay;
|
|
case 'driver_arrived':
|
|
return l10n.arrivedAtPickup;
|
|
case 'in_progress':
|
|
return l10n.tripInProgress;
|
|
case 'completed':
|
|
return l10n.tripCompleted;
|
|
default:
|
|
return l10n.trip;
|
|
}
|
|
}
|
|
|
|
void _showCancelDialog(BuildContext context, AppLocalizations l10n) {
|
|
final cs = Theme.of(context).colorScheme;
|
|
showDialog(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
title: Text(l10n.cancelTrip),
|
|
content: Text(l10n.cancelTripConfirm),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(ctx),
|
|
child: Text(l10n.no),
|
|
),
|
|
TextButton(
|
|
onPressed: () {
|
|
Navigator.pop(ctx);
|
|
context.read<DriverTripBloc>().add(const DriverTripCancelRequested());
|
|
},
|
|
style: TextButton.styleFrom(foregroundColor: cs.error),
|
|
child: Text(l10n.yes),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _InfoRow extends StatelessWidget {
|
|
final Color dotColor;
|
|
final String label;
|
|
|
|
const _InfoRow({required this.dotColor, required this.label});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
children: [
|
|
Container(
|
|
width: 10,
|
|
height: 10,
|
|
decoration: BoxDecoration(
|
|
color: dotColor,
|
|
shape: BoxShape.circle,
|
|
),
|
|
),
|
|
const SizedBox(width: T.s8),
|
|
Expanded(
|
|
child: Text(
|
|
label,
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|