feat: implement core architecture, design system, localization, and trip features for both driver and rider apps.
This commit is contained in:
@@ -0,0 +1,212 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:driver/core/l10n/app_localizations.dart';
|
||||
import '../../../core/design/tokens.dart';
|
||||
import '../../../core/ui/tripz_text_field.dart';
|
||||
import '../../trip/data/driver_trip_repository.dart';
|
||||
import '../../trip/data/models/chat_message_model.dart';
|
||||
import '../../../core/storage/token_store.dart';
|
||||
import '../../../core/di.dart';
|
||||
|
||||
/// شاشة دردشة السائق مع العميل داخل الرحلة.
|
||||
///
|
||||
/// تُستخدم من شاشة تنفيذ الرحلة (Q4).
|
||||
class DriverChatScreen extends StatefulWidget {
|
||||
final String tripId;
|
||||
|
||||
const DriverChatScreen({super.key, required this.tripId});
|
||||
|
||||
@override
|
||||
State<DriverChatScreen> createState() => _DriverChatScreenState();
|
||||
}
|
||||
|
||||
class _DriverChatScreenState extends State<DriverChatScreen> {
|
||||
final TextEditingController _controller = TextEditingController();
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
late final DriverTripRepository _repo;
|
||||
List<ChatMessageModel> _messages = [];
|
||||
bool _loading = true;
|
||||
bool _sending = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_repo = DriverTripRepository(getIt());
|
||||
_loadMessages();
|
||||
}
|
||||
|
||||
Future<void> _loadMessages() async {
|
||||
final userId = await getIt<TokenStore>().access();
|
||||
final messages = await _repo.getMessages(widget.tripId, currentUserId: userId);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_messages = messages;
|
||||
_loading = false;
|
||||
});
|
||||
_scrollToBottom();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _sendMessage() async {
|
||||
final text = _controller.text.trim();
|
||||
if (text.isEmpty || _sending) return;
|
||||
|
||||
setState(() => _sending = true);
|
||||
_controller.clear();
|
||||
|
||||
final userId = await getIt<TokenStore>().access();
|
||||
final msg = await _repo.sendMessage(widget.tripId, text, currentUserId: userId);
|
||||
if (msg != null && mounted) {
|
||||
setState(() => _messages.add(msg));
|
||||
_scrollToBottom();
|
||||
}
|
||||
if (mounted) setState(() => _sending = false);
|
||||
}
|
||||
|
||||
void _scrollToBottom() {
|
||||
Future.delayed(const Duration(milliseconds: 100), () {
|
||||
if (_scrollController.hasClients) {
|
||||
_scrollController.animateTo(
|
||||
_scrollController.position.maxScrollExtent,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(l10n.chat),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
// الرسائل
|
||||
Expanded(
|
||||
child: _loading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _messages.isEmpty
|
||||
? Center(
|
||||
child: Text(
|
||||
l10n.noMessagesYet,
|
||||
style: TextStyle(color: cs.onSurfaceVariant),
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
controller: _scrollController,
|
||||
padding: const EdgeInsets.all(T.s16),
|
||||
itemCount: _messages.length,
|
||||
itemBuilder: (context, index) {
|
||||
final msg = _messages[index];
|
||||
return _MessageBubble(message: msg);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// حقل الإرسال
|
||||
Container(
|
||||
padding: const EdgeInsets.all(T.s12),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surface,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.05),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, -2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TripzTextField(
|
||||
controller: _controller,
|
||||
hint: l10n.typeMessage,
|
||||
onSubmitted: (_) => _sendMessage(),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: T.s8),
|
||||
IconButton(
|
||||
onPressed: _sending ? null : _sendMessage,
|
||||
icon: _sending
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Icon(Icons.send, color: cs.primary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MessageBubble extends StatelessWidget {
|
||||
final ChatMessageModel message;
|
||||
|
||||
const _MessageBubble({required this.message});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return Align(
|
||||
alignment: message.isMe ? Alignment.centerRight : Alignment.centerLeft,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: T.s8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: T.s12,
|
||||
vertical: T.s8,
|
||||
),
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: MediaQuery.of(context).size.width * 0.75,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: message.isMe ? cs.primary : cs.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(T.r12).copyWith(
|
||||
bottomRight: message.isMe ? const Radius.circular(4) : null,
|
||||
bottomLeft: !message.isMe ? const Radius.circular(4) : null,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
message.text,
|
||||
style: TextStyle(
|
||||
color: message.isMe ? cs.onPrimary : cs.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'${message.createdAt.hour.toString().padLeft(2, '0')}:${message.createdAt.minute.toString().padLeft(2, '0')}',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: message.isMe
|
||||
? cs.onPrimary.withValues(alpha: 0.7)
|
||||
: cs.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
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,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:driver/core/l10n/app_localizations.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:driver/core/design/tokens.dart';
|
||||
import 'package:driver/core/design/tripz_colors.dart';
|
||||
import 'package:driver/features/trip/bloc/driver_trip_bloc.dart';
|
||||
|
||||
/// زر الإجراء التالي في شاشة تنفيذ الرحلة.
|
||||
///
|
||||
/// الحالة → الزر:
|
||||
/// - assigned → "في الطريق" (driver_arriving)
|
||||
/// - driver_arriving → "وصلت" (driver_arrived)
|
||||
/// - driver_arrived → "بدء الرحلة" (in_progress)
|
||||
/// - in_progress → "إتمام" (completed)
|
||||
class TripActionButton extends StatelessWidget {
|
||||
final dynamic trip;
|
||||
|
||||
const TripActionButton({super.key, required this.trip});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
final bloc = context.watch<DriverTripBloc>();
|
||||
final state = bloc.state;
|
||||
|
||||
final nextStatus = state.nextStatus;
|
||||
if (nextStatus == null) return const SizedBox.shrink();
|
||||
|
||||
final label = _buttonLabel(l10n, nextStatus);
|
||||
final color = nextStatus == 'completed'
|
||||
? context.tripzColors.success
|
||||
: cs.primary;
|
||||
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// أزرار ثانوية
|
||||
Row(
|
||||
children: [
|
||||
if (trip.clientPhone != null) ...[
|
||||
Expanded(
|
||||
child: _SecondaryButton(
|
||||
icon: Icons.phone,
|
||||
label: l10n.callClient,
|
||||
onTap: () => _launchPhone(trip.clientPhone!),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: T.s8),
|
||||
],
|
||||
Expanded(
|
||||
child: _SecondaryButton(
|
||||
icon: Icons.chat_bubble_outline,
|
||||
label: l10n.chat,
|
||||
onTap: () {
|
||||
// TODO: Q4 chat screen
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: T.s12),
|
||||
|
||||
// زر الإجراء الرئيسي
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: T.buttonHeight,
|
||||
child: ElevatedButton(
|
||||
onPressed: state.loading
|
||||
? null
|
||||
: () {
|
||||
bloc.add(DriverTripStatusChanged(nextStatus));
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: color,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
),
|
||||
elevation: 0,
|
||||
),
|
||||
child: state.loading
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _buttonLabel(AppLocalizations l10n, String status) {
|
||||
switch (status) {
|
||||
case 'driver_arriving':
|
||||
return l10n.onTheWay;
|
||||
case 'driver_arrived':
|
||||
return l10n.arrivedAtPickup;
|
||||
case 'in_progress':
|
||||
return l10n.startTrip;
|
||||
case 'completed':
|
||||
return l10n.completeTrip;
|
||||
default:
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
void _launchPhone(String phone) async {
|
||||
final uri = Uri(scheme: 'tel', path: phone);
|
||||
if (await canLaunchUrl(uri)) {
|
||||
await launchUrl(uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// زر ثانوي صغير.
|
||||
class _SecondaryButton extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final VoidCallback onTap;
|
||||
|
||||
const _SecondaryButton({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return OutlinedButton(
|
||||
onPressed: onTap,
|
||||
style: OutlinedButton.styleFrom(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
),
|
||||
minimumSize: const Size(0, T.buttonHeight),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, size: 18),
|
||||
const SizedBox(width: T.s4),
|
||||
Text(label),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user