feat: implement core architecture, design system, localization, and trip features for both driver and rider apps.
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:driver/core/l10n/app_localizations.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:driver/core/design/tokens.dart';
|
||||
import 'package:driver/core/design/tripz_colors.dart';
|
||||
import 'package:driver/features/home/cubit/driver_cubit.dart';
|
||||
|
||||
/// مؤشر حالة السائق — يعرض "مُتصل" أو "مُنقطع" مع زر التبديل.
|
||||
class DriverStatusIndicator extends StatelessWidget {
|
||||
const DriverStatusIndicator({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return BlocBuilder<DriverCubit, DriverState>(
|
||||
builder: (context, state) {
|
||||
final isOnline = state.online;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: T.s16,
|
||||
vertical: T.s12,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surface,
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.1),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, -4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// معلومات السائق
|
||||
if (state.profile != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: T.s8),
|
||||
child: 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(
|
||||
state.profile!.name ?? l10n.anonymous,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
if (state.profile!.vehicleMake != null)
|
||||
Text(
|
||||
'${state.profile!.vehicleMake} ${state.profile!.vehicleModel ?? ""} · ${state.profile!.plateNumber ?? ""}',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall
|
||||
?.copyWith(
|
||||
color: cs.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// زر التبديل
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: T.buttonHeight,
|
||||
child: ElevatedButton(
|
||||
onPressed: state.loading
|
||||
? null
|
||||
: () => context.read<DriverCubit>().toggleOnline(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: isOnline
|
||||
? context.tripzColors.danger
|
||||
: cs.primary,
|
||||
foregroundColor: isOnline ? Colors.white : cs.onPrimary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
),
|
||||
elevation: 0,
|
||||
),
|
||||
child: state.loading
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
isOnline
|
||||
? Icons.stop_rounded
|
||||
: Icons.play_arrow_rounded,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: T.s8),
|
||||
Text(
|
||||
isOnline ? l10n.goOffline : l10n.goOnline,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:driver/core/l10n/app_localizations.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:driver/core/design/tokens.dart';
|
||||
import 'package:driver/core/design/tripz_colors.dart';
|
||||
import 'package:driver/features/home/data/models/trip_offer_model.dart';
|
||||
import 'package:driver/features/offers/bloc/offers_bloc.dart';
|
||||
|
||||
/// بطاقة عرض الرحلة الواردة — تُعرض في overlay.
|
||||
///
|
||||
/// تتضمن:
|
||||
/// - نقاط pickup/dropoff على الخريطة المصغرة
|
||||
/// - معلومات المسافة والأجرة والوقت
|
||||
/// - عداد تنازلي للمهلة
|
||||
/// - أزرار قبول/رفض
|
||||
class TripOfferCard extends StatefulWidget {
|
||||
final TripOfferModel offer;
|
||||
|
||||
const TripOfferCard({super.key, required this.offer});
|
||||
|
||||
@override
|
||||
State<TripOfferCard> createState() => _TripOfferCardState();
|
||||
}
|
||||
|
||||
class _TripOfferCardState extends State<TripOfferCard> {
|
||||
Timer? _countdownTimer;
|
||||
int _remainingSeconds = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_remainingSeconds = widget.offer.expiresAt.difference(DateTime.now()).inSeconds;
|
||||
_countdownTimer = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_remainingSeconds = widget.offer.expiresAt.difference(DateTime.now()).inSeconds;
|
||||
if (_remainingSeconds <= 0) {
|
||||
_countdownTimer?.cancel();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_countdownTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
final progress = _remainingSeconds > 0
|
||||
? (_remainingSeconds / 30.0).clamp(0.0, 1.0)
|
||||
: 0.0;
|
||||
|
||||
return Container(
|
||||
constraints: const BoxConstraints(maxHeight: 280),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surface,
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.12),
|
||||
blurRadius: 16,
|
||||
offset: const Offset(0, 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// شريط التقدم (العد التنازلي)
|
||||
LinearProgressIndicator(
|
||||
value: progress,
|
||||
backgroundColor: cs.surfaceContainerHighest,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
_remainingSeconds > 10 ? cs.primary : context.tripzColors.danger,
|
||||
),
|
||||
minHeight: 4,
|
||||
),
|
||||
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(T.s16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// الأجرة + العداد
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
widget.offer.formattedFare,
|
||||
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: cs.primary,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: T.s8,
|
||||
vertical: T.s4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: _remainingSeconds > 10
|
||||
? cs.primaryContainer
|
||||
: context.tripzColors.danger.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(T.r8),
|
||||
),
|
||||
child: Text(
|
||||
'${_remainingSeconds > 0 ? _remainingSeconds : 0}s',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _remainingSeconds > 10
|
||||
? cs.onPrimaryContainer
|
||||
: context.tripzColors.danger,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: T.s12),
|
||||
|
||||
// المسافة والوقت
|
||||
Row(
|
||||
children: [
|
||||
_InfoChip(
|
||||
icon: Icons.straighten,
|
||||
label: widget.offer.formattedDistance,
|
||||
),
|
||||
const SizedBox(width: T.s8),
|
||||
_InfoChip(
|
||||
icon: Icons.access_time,
|
||||
label: '${widget.offer.etaPickup} ${l10n.min}',
|
||||
),
|
||||
const SizedBox(width: T.s8),
|
||||
_InfoChip(
|
||||
icon: Icons.local_taxi,
|
||||
label: widget.offer.vehicleClass,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
const SizedBox(height: T.s12),
|
||||
|
||||
// نقاط pickup وdropoff
|
||||
_LocationDot(
|
||||
color: const Color(0xFF4CAF50),
|
||||
label: widget.offer.pickupAddress ?? l10n.pickupLocation,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 7),
|
||||
child: Container(
|
||||
width: 2,
|
||||
height: T.s16,
|
||||
color: cs.outlineVariant,
|
||||
),
|
||||
),
|
||||
_LocationDot(
|
||||
color: const Color(0xFFF44336),
|
||||
label: widget.offer.dropoffAddress ?? l10n.dropoffLocation,
|
||||
),
|
||||
|
||||
const SizedBox(height: T.s16),
|
||||
|
||||
// أزرار القبول/الرفض
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: () {
|
||||
context.read<OffersBloc>().add(
|
||||
OfferRejected(widget.offer.tripId),
|
||||
);
|
||||
},
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: cs.error,
|
||||
side: BorderSide(color: cs.error),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
),
|
||||
minimumSize: const Size(0, T.buttonHeight),
|
||||
),
|
||||
child: Text(l10n.reject),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: T.s12),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
context.read<OffersBloc>().add(
|
||||
OfferAccepted(widget.offer.tripId),
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: cs.primary,
|
||||
foregroundColor: cs.onPrimary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(T.r12),
|
||||
),
|
||||
minimumSize: const Size(0, T.buttonHeight),
|
||||
elevation: 0,
|
||||
),
|
||||
child: Text(l10n.accept),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// رقاقة معلومات صغيرة (مسافة / وقت / فئة).
|
||||
class _InfoChip extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
|
||||
const _InfoChip({required this.icon, required this.label});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: T.s8, vertical: T.s4),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(T.r8),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 14, color: cs.onSurfaceVariant),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: cs.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// نقطة موقع مع لون وعنوان.
|
||||
class _LocationDot extends StatelessWidget {
|
||||
final Color color;
|
||||
final String label;
|
||||
|
||||
const _LocationDot({required this.color, required this.label});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 12,
|
||||
height: 12,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: T.s8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.bodyMedium,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user