25-10-11/1
This commit is contained in:
@@ -1,19 +1,22 @@
|
||||
// lib/views/navigation_view.dart
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'dart:ui';
|
||||
import 'dart:ui'; // For BackdropFilter
|
||||
|
||||
import 'navigation_controller.dart'; // For BackdropFilter
|
||||
import 'navigation_controller.dart';
|
||||
|
||||
// استخدام نفس مسار الاستيراد الذي قدمته
|
||||
// ملاحظة: افترضتُ أن لديك لوناً أساسياً في هذا الملف
|
||||
// import 'package:sefer_driver/constant/colors.dart';
|
||||
// سأستخدم اللون الأزرق كبديل مؤقت
|
||||
const Color kPrimaryColor = Color(0xFF0D47A1);
|
||||
|
||||
class NavigationView extends StatelessWidget {
|
||||
const NavigationView({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// استخدام Get.find() بدلاً من Get.put() لضمان أن الكونترولر مُهيأ مسبقاً
|
||||
// إذا كانت هذه هي نقطة الدخول، Get.put() صحيح.
|
||||
final NavigationController controller = Get.put(NavigationController());
|
||||
|
||||
return Scaffold(
|
||||
@@ -23,7 +26,6 @@ class NavigationView extends StatelessWidget {
|
||||
// --- الخريطة ---
|
||||
GoogleMap(
|
||||
onMapCreated: controller.onMapCreated,
|
||||
// --- السطر المضاف والمهم هنا ---
|
||||
onLongPress: controller.onMapLongPressed,
|
||||
initialCameraPosition: CameraPosition(
|
||||
target: controller.myLocation ??
|
||||
@@ -37,27 +39,33 @@ class NavigationView extends StatelessWidget {
|
||||
compassEnabled: false,
|
||||
zoomControlsEnabled: false,
|
||||
// تعديل الـ padding لإعطاء مساحة للعناصر العلوية والسفلية
|
||||
// مساحة أكبر في الأعلى للبحث + النتائج، ومساحة أكبر بالأسفل للملاحة
|
||||
padding: EdgeInsets.only(
|
||||
bottom: controller.currentInstruction.isNotEmpty ? 130 : 0,
|
||||
top: 140),
|
||||
bottom: controller.currentInstruction.isNotEmpty ? 170 : 0,
|
||||
top: 150,
|
||||
),
|
||||
),
|
||||
|
||||
// --- واجهة البحث ونتائجه ---
|
||||
_buildSearchUI(controller),
|
||||
// --- واجهة البحث (تصميم زجاجي) ---
|
||||
_buildGlassSearchUI(controller),
|
||||
|
||||
// --- إرشادات الملاحة المطورة ---
|
||||
// --- إرشادات الملاحة (تصميم عائم) ---
|
||||
if (controller.currentInstruction.isNotEmpty)
|
||||
_buildNavigationInstruction(controller),
|
||||
_buildFloatingNavigationUI(controller),
|
||||
|
||||
// --- أزرار التحكم على الخريطة ---
|
||||
_buildMapControls(controller),
|
||||
// --- أزرار التحكم (تصميم عائم) ---
|
||||
_buildFloatingMapControls(controller),
|
||||
|
||||
// --- مؤشر التحميل ---
|
||||
if (controller.isLoading)
|
||||
Container(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(color: Colors.white)),
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
strokeWidth: 3,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -65,94 +73,75 @@ class NavigationView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
// --- ويدجت خاصة بواجهة البحث ---
|
||||
Widget _buildSearchUI(NavigationController controller) {
|
||||
/// --- 1. واجهة البحث بالتصميم الزجاجي المطور ---
|
||||
Widget _buildGlassSearchUI(NavigationController controller) {
|
||||
return Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(15.0),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.15),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 5),
|
||||
// --- شريط البحث ---
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(28.0),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
|
||||
child: Container(
|
||||
height: 56,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.85),
|
||||
borderRadius: BorderRadius.circular(28.0),
|
||||
border: Border.all(color: Colors.white.withOpacity(0.4)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 15,
|
||||
offset: const Offset(0, 5),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(left: 18.0, right: 10.0),
|
||||
child: Icon(Icons.search,
|
||||
color: kPrimaryColor, size: 24),
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: controller.placeDestinationController,
|
||||
onChanged: controller.onSearchChanged,
|
||||
textInputAction: TextInputAction.search,
|
||||
style: const TextStyle(
|
||||
fontSize: 16, color: Colors.black87),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'إلى أين تريد الذهاب؟',
|
||||
hintStyle: const TextStyle(
|
||||
color: Colors.black45, fontSize: 16),
|
||||
border: InputBorder.none,
|
||||
contentPadding: const EdgeInsets.only(bottom: 2),
|
||||
),
|
||||
),
|
||||
),
|
||||
// زر المسح أو إلغاء المسار
|
||||
if (controller
|
||||
.placeDestinationController.text.isNotEmpty)
|
||||
_buildClearButton(controller)
|
||||
else if (controller.polylines.isNotEmpty)
|
||||
_buildCancelRouteButton(controller),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
child: TextField(
|
||||
controller: controller.placeDestinationController,
|
||||
onChanged: (val) {
|
||||
controller.onSearchChanged(val);
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: 'إلى أين تريد الذهاب؟',
|
||||
prefixIcon: const Icon(Icons.search, color: Colors.grey),
|
||||
suffixIcon: controller
|
||||
.placeDestinationController.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear, color: Colors.grey),
|
||||
onPressed: () {
|
||||
controller.placeDestinationController.clear();
|
||||
controller.placesDestination = [];
|
||||
controller.update();
|
||||
},
|
||||
)
|
||||
: (controller.polylines.isNotEmpty
|
||||
? IconButton(
|
||||
icon:
|
||||
const Icon(Icons.close, color: Colors.red),
|
||||
tooltip: 'إلغاء المسار',
|
||||
onPressed: () => controller.clearRoute(),
|
||||
)
|
||||
: null),
|
||||
border: InputBorder.none,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 20, vertical: 15),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// --- قائمة النتائج ---
|
||||
if (controller.placesDestination.isNotEmpty)
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(15.0),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(maxHeight: 220),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.85),
|
||||
borderRadius: BorderRadius.circular(15.0),
|
||||
),
|
||||
child: ListView.builder(
|
||||
padding: EdgeInsets.zero,
|
||||
shrinkWrap: true,
|
||||
itemCount: controller.placesDestination.length,
|
||||
itemBuilder: (context, index) {
|
||||
final place = controller.placesDestination[index];
|
||||
return ListTile(
|
||||
title: Text(place['name'] ?? 'اسم غير معروف',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold)),
|
||||
subtitle: Text(place['address'] ?? '',
|
||||
maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
leading: const Icon(Icons.location_on_outlined,
|
||||
color: Colors.blue),
|
||||
onTap: () => controller.selectDestination(place),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildSearchResultsList(controller),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -160,28 +149,136 @@ class NavigationView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
// --- ويدجت خاصة بأزرار التحكم ---
|
||||
Widget _buildMapControls(NavigationController controller) {
|
||||
Widget _buildClearButton(NavigationController controller) {
|
||||
return IconButton(
|
||||
icon: const Icon(Icons.clear, color: Colors.grey, size: 22),
|
||||
onPressed: () {
|
||||
controller.placeDestinationController.clear();
|
||||
controller.placesDestination = [];
|
||||
controller.update();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCancelRouteButton(NavigationController controller) {
|
||||
return IconButton(
|
||||
tooltip: 'إلغاء المسار',
|
||||
icon: const Icon(Icons.close, color: Colors.redAccent, size: 22),
|
||||
onPressed: () => controller.clearRoute(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchResultsList(NavigationController controller) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(maxHeight: 220),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.85),
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
border: Border.all(color: Colors.white.withOpacity(0.4)),
|
||||
),
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
itemCount: controller.placesDestination.length,
|
||||
itemBuilder: (context, index) {
|
||||
final place = controller.placesDestination[index];
|
||||
final distance = place['distanceKm'] as double?;
|
||||
final address = (place['address'] ?? '').toString();
|
||||
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () => controller.selectDestination(place),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0, vertical: 12.0),
|
||||
child: Row(
|
||||
children: [
|
||||
// أيقونة الموقع
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: kPrimaryColor.withOpacity(0.1),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.location_on_outlined,
|
||||
color: kPrimaryColor, size: 20),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
// الاسم والعنوان
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
place['name'] ?? 'اسم غير معروف',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 16,
|
||||
color: Colors.black87),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
if (address.isNotEmpty)
|
||||
Text(
|
||||
address,
|
||||
style: const TextStyle(
|
||||
color: Colors.black54, fontSize: 13),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
// المسافة
|
||||
if (distance != null)
|
||||
Text(
|
||||
'${distance.toStringAsFixed(1)} كم',
|
||||
style: const TextStyle(
|
||||
color: kPrimaryColor,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// --- 2. أزرار التحكم بالتصميم العائم ---
|
||||
Widget _buildFloatingMapControls(NavigationController controller) {
|
||||
return Positioned(
|
||||
bottom: controller.currentInstruction.isNotEmpty ? 150 : 20,
|
||||
right: 12,
|
||||
// اجعلها تطفو فوق لوحة الملاحة
|
||||
bottom: controller.currentInstruction.isNotEmpty ? 190 : 24,
|
||||
right: 16,
|
||||
child: Column(
|
||||
children: [
|
||||
if (controller.polylines.isNotEmpty) ...[
|
||||
FloatingActionButton(
|
||||
heroTag: 'rerouteBtn',
|
||||
mini: true,
|
||||
backgroundColor: Colors.white,
|
||||
tooltip: 'إعادة حساب المسار',
|
||||
elevation: 6,
|
||||
onPressed: () => controller.recalculateRoute(),
|
||||
child: const Icon(Icons.sync_alt, color: Colors.blue),
|
||||
tooltip: 'إعادة حساب المسار',
|
||||
child: const Icon(Icons.sync_alt, color: kPrimaryColor, size: 24),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
FloatingActionButton(
|
||||
heroTag: 'gpsBtn',
|
||||
mini: true,
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 6,
|
||||
onPressed: () {
|
||||
if (controller.myLocation != null) {
|
||||
controller.animateCameraToPosition(
|
||||
@@ -191,102 +288,134 @@ class NavigationView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Icon(Icons.gps_fixed, color: Colors.black54),
|
||||
child: const Icon(Icons.gps_fixed, color: Colors.black54, size: 24),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// --- ويدجت خاصة بإرشادات الطريق المطورة ---
|
||||
Widget _buildNavigationInstruction(NavigationController controller) {
|
||||
/// --- 3. واجهة الملاحة بالتصميم العائم المطور ---
|
||||
Widget _buildFloatingNavigationUI(NavigationController controller) {
|
||||
return Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 16,
|
||||
left: 16,
|
||||
right: 16,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Colors.blue.shade900, Colors.blue.shade600],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
gradient: const LinearGradient(
|
||||
colors: [Color(0xFF1E88E5), Color(0xFF0D47A1)], // أزرق متدرج
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(28),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.2),
|
||||
blurRadius: 15,
|
||||
offset: const Offset(0, -5),
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
blurRadius: 25,
|
||||
offset: const Offset(0, 10),
|
||||
),
|
||||
],
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
topRight: Radius.circular(20),
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 20),
|
||||
padding: const EdgeInsets.fromLTRB(22, 20, 22, 22),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// --- الصف العلوي: السرعة والمسافة ---
|
||||
// --- الصف العلوي: الإرشاد والمسافة ---
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// الأيقونة
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.navigation_rounded,
|
||||
color: Colors.white, size: 28),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
// الإرشاد
|
||||
Expanded(
|
||||
child: Text(
|
||||
controller.currentInstruction,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
height: 1.3,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
// المسافة
|
||||
Text(
|
||||
controller.distanceToNextStep,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold),
|
||||
color: Colors.white,
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// --- فاصل ---
|
||||
if (controller.nextInstruction.isNotEmpty ||
|
||||
controller.currentSpeed > 0)
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 14.0),
|
||||
child: Divider(color: Colors.white30, height: 1),
|
||||
),
|
||||
|
||||
// --- الصف السفلي: الإرشاد التالي والسرعة ---
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// الإرشاد التالي
|
||||
Expanded(
|
||||
child: controller.nextInstruction.isNotEmpty
|
||||
? Text(
|
||||
'التالي: ${controller.nextInstruction}',
|
||||
style: const TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
)
|
||||
: const SizedBox(), // يترك مساحة فارغة إذا لم يكن هناك إرشاد تالي
|
||||
),
|
||||
|
||||
// السرعة
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
controller.currentSpeed.toStringAsFixed(0),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold),
|
||||
color: Colors.white,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
const SizedBox(width: 6),
|
||||
const Text(
|
||||
"كم/س",
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14),
|
||||
'كم/س',
|
||||
style: TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(color: Colors.white38, height: 20, thickness: 0.8),
|
||||
// --- الصف السفلي: الإرشاد القادم ---
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.navigation_rounded,
|
||||
color: Colors.white, size: 32),
|
||||
const SizedBox(width: 15),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text("الخطوة التالية",
|
||||
style:
|
||||
TextStyle(color: Colors.white70, fontSize: 12)),
|
||||
Text(
|
||||
controller.nextInstruction.isNotEmpty
|
||||
? controller.nextInstruction
|
||||
: controller.currentInstruction,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user