88 lines
3.1 KiB
Dart
88 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
/// شارة «رحلة مجدولة».
|
|
///
|
|
/// السائق يجب أن يعرف أن هذه ليست رحلة لحظية بل موعد مضبوط: الراكب
|
|
/// ينتظره في وقت محدد، والتأخر عليه يختلف عن التأخر على طلب فوري.
|
|
///
|
|
/// المصدر: حقلا `is_scheduled` و`scheduled_at` في حمولة الرحلة —
|
|
/// يضيفهما buildMarketPayload في backend/ride/rides/add_ride.php.
|
|
/// غيابهما = رحلة عادية، فلا تظهر الشارة إطلاقاً.
|
|
///
|
|
/// بخلاف شارة «طلب خاص/عام» التي تظهر في نافذة العرض فقط، هذه تظهر في
|
|
/// **كل** السطوح: القائمة، ونافذة الطلب، والأوفرلي — لأن القيمة هنا
|
|
/// معلومة دائمة عن الرحلة لا حالة مؤقتة تنقضي بعد ثوانٍ.
|
|
class ScheduledRideBadge extends StatelessWidget {
|
|
final Map rideInfo;
|
|
|
|
/// حجم مصغّر لبطاقات القائمة.
|
|
final bool compact;
|
|
|
|
const ScheduledRideBadge({
|
|
super.key,
|
|
required this.rideInfo,
|
|
this.compact = false,
|
|
});
|
|
|
|
static bool isScheduled(Map? info) {
|
|
final v = info?['is_scheduled']?.toString();
|
|
return v == '1' || v == 'true';
|
|
}
|
|
|
|
/// وقت الموعد بصيغة قصيرة. يرجع فارغاً إن لم يصل أو تعذّر تحليله —
|
|
/// الشارة تبقى ظاهرة بلا وقت بدل أن تختفي.
|
|
String get _timeLabel {
|
|
final raw = rideInfo['scheduled_at']?.toString();
|
|
if (raw == null || raw.isEmpty) return '';
|
|
|
|
final dt = DateTime.tryParse(raw);
|
|
if (dt == null) return '';
|
|
|
|
final now = DateTime.now();
|
|
final sameDay =
|
|
dt.year == now.year && dt.month == now.month && dt.day == now.day;
|
|
|
|
final hh = dt.hour.toString().padLeft(2, '0');
|
|
final mm = dt.minute.toString().padLeft(2, '0');
|
|
|
|
if (sameDay) return '$hh:$mm';
|
|
return '${dt.day}/${dt.month} $hh:$mm';
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (!isScheduled(rideInfo)) return const SizedBox.shrink();
|
|
|
|
const color = Color(0xFF6A5ACD); // بنفسجي — لا يشبه ألوان الحالات الأخرى
|
|
final t = _timeLabel;
|
|
|
|
return Container(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: compact ? 8 : 12,
|
|
vertical: compact ? 4 : 6,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: color.withOpacity(0.12),
|
|
borderRadius: BorderRadius.circular(compact ? 12 : 20),
|
|
border: Border.all(color: color.withOpacity(0.5)),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(Icons.schedule, color: color, size: compact ? 14 : 16),
|
|
const SizedBox(width: 4),
|
|
Text(
|
|
t.isEmpty ? 'رحلة مجدولة'.tr : '${'رحلة مجدولة'.tr} · $t',
|
|
style: TextStyle(
|
|
color: color,
|
|
fontSize: compact ? 11 : 13,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|