إصلاح توافق فلاتر مع Theme الجديد

This commit is contained in:
Hamza-Ayed
2026-07-26 11:33:20 +03:00
parent 7830efead7
commit 3af99cc18a
31 changed files with 4256 additions and 2833 deletions
@@ -4,14 +4,9 @@ import 'package:get/get.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:siro_admin/constant/links.dart';
// Keep your specific imports
import 'package:siro_admin/controller/functions/crud.dart';
import 'package:siro_admin/views/widgets/snackbar.dart';
/// --------------------------------------------------------------------------
/// 1. DATA MODELS
/// --------------------------------------------------------------------------
class DriverLocation {
final double latitude;
final double longitude;
@@ -38,32 +33,21 @@ class DriverLocation {
}
}
/// --------------------------------------------------------------------------
/// 2. GETX CONTROLLER
/// --------------------------------------------------------------------------
/// تطبيع رقم الهاتف تلقائياً حسب الدولة
/// مثال: 0992952235 ← 963992952235 (سوريا)
/// مثال: 079XXXXXXX ← 96279XXXXXXX (أردن)
/// مثال: 010XXXXXXXX ← 2010XXXXXXXX (مصر)
String normalizePhone(String input) {
final clean = input.replaceAll(RegExp(r'\D+'), '');
// Syria: 099XXXXXXX or 9639XXXXXXX
if (clean.length == 10 && clean.startsWith('09')) {
return '963${clean.substring(1)}';
}
if (clean.length == 12 && clean.startsWith('963')) return clean;
if (clean.length == 9 && clean.startsWith('9')) return '963$clean';
// Jordan: 079XXXXXXX or 9627XXXXXXX
if (clean.length == 10 && clean.startsWith('07')) {
return '962${clean.substring(1)}';
}
if (clean.length == 12 && clean.startsWith('962')) return clean;
if (clean.length == 9 && clean.startsWith('7')) return '962$clean';
// Egypt: 010XXXXXXXX or 2010XXXXXXXX
if (clean.length == 11 && clean.startsWith('01')) {
return '20${clean.substring(1)}';
}
@@ -73,32 +57,26 @@ String normalizePhone(String input) {
}
class RideMonitorController extends GetxController {
// CONFIGURATION
final String apiUrl = "${AppLink.server}/Admin/rides/monitorRide.php";
// INPUT CONTROLLERS
final TextEditingController phoneInputController = TextEditingController();
// OBSERVABLES
var isTracking = false.obs;
var isLoading = false.obs;
var hasError = false.obs;
var errorMessage = ''.obs;
// Driver & Ride Data
var driverLocation = Rxn<DriverLocation>();
var driverName = "Unknown Driver".obs;
var rideStatus = "Waiting...".obs;
// Route Data
var startPoint = Rxn<LatLng>();
var endPoint = Rxn<LatLng>();
var routePolyline = <LatLng>[].obs; // List of points for the line
var routePolyline = <LatLng>[].obs;
// Map Variables
final MapController mapController = MapController();
Timer? _timer;
bool _isFirstLoad = true; // To trigger auto-fit bounds only on first success
bool _isFirstLoad = true;
@override
void onClose() {
@@ -107,15 +85,12 @@ class RideMonitorController extends GetxController {
super.onClose();
}
// --- ACTIONS ---
void startSearch() {
if (phoneInputController.text.trim().isEmpty) {
mySnackbarWarning("يرجى إدخال رقم الهاتف أولاً");
return;
}
// Reset state
hasError.value = false;
errorMessage.value = '';
driverLocation.value = null;
@@ -126,14 +101,11 @@ class RideMonitorController extends GetxController {
rideStatus.value = "جاري التحميل...";
_isFirstLoad = true;
// Switch UI
isTracking.value = true;
isLoading.value = true;
// Start fetching
fetchRideData();
// Start Polling
_timer?.cancel();
_timer = Timer.periodic(const Duration(seconds: 10), (timer) {
fetchRideData();
@@ -144,7 +116,6 @@ class RideMonitorController extends GetxController {
_timer?.cancel();
isTracking.value = false;
isLoading.value = false;
// phoneInputController.clear(); // اختياري: يمكنك إبقائه لتسهيل البحث مرة أخرى
}
Future<void> fetchRideData() async {
@@ -152,7 +123,6 @@ class RideMonitorController extends GetxController {
if (phone.isEmpty) return;
try {
// تطبيع رقم الهاتف تلقائياً حسب الدولة
String normalizedPhone = normalizePhone(phone);
final response = await CRUD().post(
link: apiUrl,
@@ -168,17 +138,14 @@ class RideMonitorController extends GetxController {
final data =
jsonResponse['message'] ?? jsonResponse['data'] ?? jsonResponse;
// 1. Parse Driver Info
if (data['driver_details'] != null) {
driverName.value =
data['driver_details']['fullname'] ?? "سائق غير معروف";
}
// 2. Parse Ride Info & Route
if (data['ride_details'] != null) {
rideStatus.value = data['ride_details']['status'] ?? "غير معروف";
// Parse Start/End Locations (Format: "lat,lng")
String? startStr = data['ride_details']['start_location'];
String? endStr = data['ride_details']['end_location'];
@@ -188,20 +155,17 @@ class RideMonitorController extends GetxController {
if (s != null && e != null) {
startPoint.value = s;
endPoint.value = e;
routePolyline.value = [s, e]; // Straight line for now
routePolyline.value = [s, e];
}
}
// 3. Parse Live Location
final locData = data['driver_location'];
if (locData is Map<String, dynamic>) {
final newLocation = DriverLocation.fromJson(locData);
driverLocation.value = newLocation;
// 4. Update Camera Bounds
_updateMapBounds();
} else {
// Even if no live driver, we might want to show the route
if (startPoint.value != null && endPoint.value != null) {
_updateMapBounds();
}
@@ -227,7 +191,6 @@ class RideMonitorController extends GetxController {
}
}
// Helper to parse "lat,lng" string
LatLng? _parseLatLngString(String? str) {
if (str == null || !str.contains(',')) return null;
try {
@@ -240,7 +203,6 @@ class RideMonitorController extends GetxController {
}
}
// Logic to fit start, end, and driver on screen
void _updateMapBounds() {
if (!_isFirstLoad) return;
@@ -264,48 +226,36 @@ class RideMonitorController extends GetxController {
);
_isFirstLoad = false;
} catch (e) {
// Map Controller not ready yet
}
}
}
}
/// --------------------------------------------------------------------------
/// 3. UI SCREEN (Modern Light Theme)
/// --------------------------------------------------------------------------
class RideMonitorScreen extends StatelessWidget {
const RideMonitorScreen({super.key});
// 🎨 الألوان العصرية (Modern Palette)
final Color backgroundColor = const Color(0xFFF4F7FE);
final Color primaryColor = const Color(0xFF4318FF);
final Color textPrimary = const Color(0xFF2B3674);
final Color textSecondary = const Color(0xFFA3AED0);
@override
Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;
final RideMonitorController controller = Get.put(RideMonitorController());
return Scaffold(
backgroundColor: backgroundColor,
// الإبقاء على AppBar فقط في شاشة البحث
backgroundColor: cs.surface,
appBar: PreferredSize(
preferredSize: const Size.fromHeight(kToolbarHeight),
child: Obx(() {
if (controller.isTracking.value) {
return const SizedBox
.shrink(); // إخفاء الـ AppBar في وضع التتبع للخريطة الكاملة
return const SizedBox.shrink();
}
return AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
centerTitle: true,
iconTheme: IconThemeData(color: textPrimary),
iconTheme: IconThemeData(color: cs.onSurface),
title: Text(
"مراقبة الرحلات",
style: TextStyle(
color: textPrimary,
color: cs.onSurface,
fontWeight: FontWeight.bold,
fontSize: 18,
),
@@ -315,18 +265,15 @@ class RideMonitorScreen extends StatelessWidget {
),
body: Obx(() {
if (!controller.isTracking.value) {
return _buildSearchForm(context, controller);
return _buildSearchForm(context, controller, cs);
}
return _buildMapTrackingView(context, controller);
return _buildMapTrackingView(context, controller, cs);
}),
);
}
// ---------------------------------------------------------------------------
// واجهة البحث (Search View)
// ---------------------------------------------------------------------------
Widget _buildSearchForm(
BuildContext context, RideMonitorController controller) {
BuildContext context, RideMonitorController controller, ColorScheme cs) {
return Center(
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
@@ -335,11 +282,11 @@ class RideMonitorScreen extends StatelessWidget {
child: Container(
padding: const EdgeInsets.all(32.0),
decoration: BoxDecoration(
color: Colors.white,
color: cs.surface,
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
color: primaryColor.withOpacity(0.08),
color: cs.primary.withValues(alpha: 0.08),
blurRadius: 24,
offset: const Offset(0, 10),
)
@@ -351,17 +298,16 @@ class RideMonitorScreen extends StatelessWidget {
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: primaryColor.withOpacity(0.1),
color: cs.primary.withValues(alpha: 0.1),
shape: BoxShape.circle,
),
child:
Icon(Icons.radar_rounded, size: 60, color: primaryColor),
child: Icon(Icons.radar_rounded, size: 60, color: cs.primary),
),
const SizedBox(height: 24),
Text(
"تتبع رحلة نشطة",
style: TextStyle(
color: textPrimary,
color: cs.onSurface,
fontSize: 22,
fontWeight: FontWeight.bold,
),
@@ -370,7 +316,7 @@ class RideMonitorScreen extends StatelessWidget {
Text(
"أدخل رقم هاتف السائق أو الراكب للبدء",
style: TextStyle(
color: textSecondary,
color: cs.onSurfaceVariant,
fontSize: 14,
),
textAlign: TextAlign.center,
@@ -378,27 +324,27 @@ class RideMonitorScreen extends StatelessWidget {
const SizedBox(height: 32),
Container(
decoration: BoxDecoration(
color: backgroundColor,
color: cs.surface,
borderRadius: BorderRadius.circular(16),
border: Border.all(color: Colors.white, width: 2),
border: Border.all(color: cs.outline, width: 2),
),
child: TextField(
controller: controller.phoneInputController,
keyboardType: TextInputType.phone,
textDirection: TextDirection.ltr,
style: TextStyle(
color: textPrimary,
color: cs.onSurface,
fontSize: 16,
fontWeight: FontWeight.w600,
),
decoration: InputDecoration(
hintText: "مثال: 0992952235...",
hintStyle: TextStyle(color: textSecondary),
hintStyle: TextStyle(color: cs.onSurfaceVariant),
border: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(
vertical: 18, horizontal: 20),
prefixIcon:
Icon(Icons.phone_rounded, color: primaryColor),
Icon(Icons.phone_rounded, color: cs.primary),
),
),
),
@@ -409,16 +355,16 @@ class RideMonitorScreen extends StatelessWidget {
child: ElevatedButton(
onPressed: controller.startSearch,
style: ElevatedButton.styleFrom(
backgroundColor: primaryColor,
backgroundColor: cs.primary,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
),
child: const Text(
child: Text(
"بدء المراقبة",
style: TextStyle(
color: Colors.white,
color: cs.onPrimary,
fontSize: 16,
fontWeight: FontWeight.bold,
),
@@ -433,11 +379,8 @@ class RideMonitorScreen extends StatelessWidget {
);
}
// ---------------------------------------------------------------------------
// واجهة الخريطة (Map View)
// ---------------------------------------------------------------------------
Widget _buildMapTrackingView(
BuildContext context, RideMonitorController controller) {
BuildContext context, RideMonitorController controller, ColorScheme cs) {
return Stack(
children: [
FlutterMap(
@@ -451,45 +394,36 @@ class RideMonitorScreen extends StatelessWidget {
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.siromove.admin',
),
// 1. ROUTE LINE (Polyline)
if (controller.routePolyline.isNotEmpty)
PolylineLayer(
polylines: [
Polyline(
points: controller.routePolyline,
strokeWidth: 6.0,
color: primaryColor.withOpacity(0.9),
color: cs.primary.withValues(alpha: 0.9),
borderStrokeWidth: 2.0,
borderColor: primaryColor.withOpacity(0.3),
borderColor: cs.primary.withValues(alpha: 0.3),
strokeCap: StrokeCap.round,
strokeJoin: StrokeJoin.round,
),
],
),
// 2. START & END MARKERS
MarkerLayer(
markers: [
// Start Point (Green Dot)
if (controller.startPoint.value != null)
Marker(
point: controller.startPoint.value!,
width: 30,
height: 30,
child: _buildPointMarker(const Color(0xFF10B981)),
child: _buildPointMarker(const Color(0xFF10B981), cs),
),
// End Point (Red Dot)
if (controller.endPoint.value != null)
Marker(
point: controller.endPoint.value!,
width: 30,
height: 30,
child: _buildPointMarker(const Color(0xFFEF4444)),
child: _buildPointMarker(const Color(0xFFEF4444), cs),
),
// Driver Car Marker
if (controller.driverLocation.value != null)
Marker(
point: LatLng(
@@ -507,11 +441,11 @@ class RideMonitorScreen extends StatelessWidget {
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white,
color: cs.surface,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
color: cs.onSurface.withValues(alpha: 0.2),
blurRadius: 10,
spreadRadius: 2,
)
@@ -519,7 +453,7 @@ class RideMonitorScreen extends StatelessWidget {
),
child: Icon(
Icons.directions_car_rounded,
color: primaryColor,
color: cs.primary,
size: 28,
),
),
@@ -528,13 +462,13 @@ class RideMonitorScreen extends StatelessWidget {
padding: const EdgeInsets.symmetric(
horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: textPrimary,
color: cs.onSurface,
borderRadius: BorderRadius.circular(6),
),
child: Text(
"${controller.driverLocation.value!.speed.toInt()} كم",
style: const TextStyle(
color: Colors.white,
style: TextStyle(
color: cs.onPrimary,
fontSize: 10,
fontWeight: FontWeight.bold,
),
@@ -549,48 +483,44 @@ class RideMonitorScreen extends StatelessWidget {
),
],
),
// زر التراجع (إيقاف التتبع) أعلى الشاشة
Positioned(
top: MediaQuery.of(context).padding.top + 10,
right: 20, // أو left حسب لغة التطبيق
right: 20,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
color: cs.surface,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
color: cs.onSurface.withValues(alpha: 0.1),
blurRadius: 10,
offset: const Offset(0, 4),
)
],
),
child: IconButton(
icon: Icon(Icons.close_rounded, color: textPrimary, size: 24),
icon: Icon(Icons.close_rounded, color: cs.onSurface, size: 24),
onPressed: controller.stopTracking,
tooltip: "إيقاف المراقبة",
),
),
),
// LOADING OVERLAY (Smooth Frosted Glass like)
if (controller.isLoading.value &&
controller.driverLocation.value == null &&
controller.startPoint.value == null)
Container(
color: Colors.white.withOpacity(0.8),
color: cs.surface.withValues(alpha: 0.8),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(
color: primaryColor, strokeWidth: 3),
color: cs.primary, strokeWidth: 3),
const SizedBox(height: 16),
Text(
"جاري تحديد الموقع...",
style: TextStyle(
color: textPrimary,
color: cs.onSurface,
fontWeight: FontWeight.bold,
fontSize: 16,
),
@@ -599,19 +529,17 @@ class RideMonitorScreen extends StatelessWidget {
),
),
),
// ERROR OVERLAY
if (controller.hasError.value)
Center(
child: Container(
margin: const EdgeInsets.all(24),
padding: const EdgeInsets.all(24),
decoration: BoxDecoration(
color: Colors.white,
color: cs.surface,
borderRadius: BorderRadius.circular(24),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
color: cs.onSurface.withValues(alpha: 0.1),
blurRadius: 20,
offset: const Offset(0, 10),
)
@@ -623,17 +551,17 @@ class RideMonitorScreen extends StatelessWidget {
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.1),
color: cs.error.withValues(alpha: 0.1),
shape: BoxShape.circle,
),
child: const Icon(Icons.error_outline_rounded,
color: Colors.red, size: 40),
child: Icon(Icons.error_outline_rounded,
color: cs.error, size: 40),
),
const SizedBox(height: 16),
Text(
"حدث خطأ",
style: TextStyle(
color: textPrimary,
color: cs.onSurface,
fontSize: 18,
fontWeight: FontWeight.bold,
),
@@ -642,7 +570,7 @@ class RideMonitorScreen extends StatelessWidget {
Text(
controller.errorMessage.value,
textAlign: TextAlign.center,
style: TextStyle(color: textSecondary, height: 1.5),
style: TextStyle(color: cs.onSurfaceVariant, height: 1.5),
),
const SizedBox(height: 24),
SizedBox(
@@ -650,8 +578,8 @@ class RideMonitorScreen extends StatelessWidget {
child: ElevatedButton(
onPressed: controller.stopTracking,
style: ElevatedButton.styleFrom(
backgroundColor: backgroundColor,
foregroundColor: textPrimary,
backgroundColor: cs.surface,
foregroundColor: cs.onSurface,
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
@@ -666,8 +594,6 @@ class RideMonitorScreen extends StatelessWidget {
),
),
),
// INFO CARD (Bottom Floating Card)
if (!controller.hasError.value && !controller.isLoading.value)
Positioned(
bottom: 30,
@@ -675,11 +601,11 @@ class RideMonitorScreen extends StatelessWidget {
right: 20,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
color: cs.surface,
borderRadius: BorderRadius.circular(24),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.08),
color: cs.onSurface.withValues(alpha: 0.08),
blurRadius: 24,
offset: const Offset(0, 10),
)
@@ -696,11 +622,11 @@ class RideMonitorScreen extends StatelessWidget {
width: 50,
height: 50,
decoration: BoxDecoration(
color: primaryColor.withOpacity(0.1),
color: cs.primary.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(15),
),
child: Icon(Icons.person_rounded,
color: primaryColor, size: 28),
color: cs.primary, size: 28),
),
const SizedBox(width: 16),
Expanded(
@@ -710,7 +636,7 @@ class RideMonitorScreen extends StatelessWidget {
Text(
controller.driverName.value,
style: TextStyle(
color: textPrimary,
color: cs.onSurface,
fontSize: 18,
fontWeight: FontWeight.bold,
),
@@ -735,7 +661,7 @@ class RideMonitorScreen extends StatelessWidget {
Text(
controller.rideStatus.value,
style: TextStyle(
color: textSecondary,
color: cs.onSurfaceVariant,
fontSize: 13,
fontWeight: FontWeight.w600,
),
@@ -759,17 +685,19 @@ class RideMonitorScreen extends StatelessWidget {
Icons.speed_rounded,
"${controller.driverLocation.value!.speed.toStringAsFixed(1)} كم/س",
const Color(0xFF3B82F6),
cs,
),
Container(
width: 1,
height: 30,
color: Colors.grey.withOpacity(0.2)),
color: cs.outline.withValues(alpha: 0.2)),
_buildModernInfoBadge(
Icons.access_time_rounded,
controller.driverLocation.value!.updatedAt
.split(' ')
.last,
const Color(0xFF8B5CF6),
cs,
),
],
)
@@ -781,13 +709,13 @@ class RideMonitorScreen extends StatelessWidget {
width: 16,
height: 16,
child: CircularProgressIndicator(
color: primaryColor, strokeWidth: 2),
color: cs.primary, strokeWidth: 2),
),
const SizedBox(width: 10),
Text(
"جاري الاتصال بالسائق...",
style: TextStyle(
color: primaryColor,
color: cs.primary,
fontWeight: FontWeight.w600,
fontSize: 13,
),
@@ -803,12 +731,10 @@ class RideMonitorScreen extends StatelessWidget {
);
}
// --- Helper Widgets ---
Widget _buildPointMarker(Color color) {
Widget _buildPointMarker(Color color, ColorScheme cs) {
return Container(
decoration: BoxDecoration(
color: color.withOpacity(0.3),
color: color.withValues(alpha: 0.3),
shape: BoxShape.circle,
),
child: Center(
@@ -818,10 +744,10 @@ class RideMonitorScreen extends StatelessWidget {
decoration: BoxDecoration(
color: color,
shape: BoxShape.circle,
border: Border.all(color: Colors.white, width: 2),
border: Border.all(color: cs.surface, width: 2),
boxShadow: [
BoxShadow(
color: color.withOpacity(0.5),
color: color.withValues(alpha: 0.5),
blurRadius: 6,
spreadRadius: 1,
)
@@ -832,13 +758,14 @@ class RideMonitorScreen extends StatelessWidget {
);
}
Widget _buildModernInfoBadge(IconData icon, String text, Color iconColor) {
Widget _buildModernInfoBadge(
IconData icon, String text, Color iconColor, ColorScheme cs) {
return Row(
children: [
Container(
padding: const EdgeInsets.all(6),
decoration: BoxDecoration(
color: iconColor.withOpacity(0.1),
color: iconColor.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
),
child: Icon(icon, size: 16, color: iconColor),
@@ -847,11 +774,11 @@ class RideMonitorScreen extends StatelessWidget {
Text(
text,
style: TextStyle(
color: textPrimary,
color: cs.onSurface,
fontSize: 14,
fontWeight: FontWeight.bold,
),
textDirection: TextDirection.ltr, // للحفاظ على اتجاه الأرقام
textDirection: TextDirection.ltr,
),
],
);