25-10-5/1
This commit is contained in:
@@ -26,7 +26,7 @@ class CarType {
|
||||
{required this.carType, required this.carDetail, required this.image});
|
||||
}
|
||||
|
||||
// --- List of Car Types with NEW order and 'Electric' car ---
|
||||
// --- List of Car Types (unchanged) ---
|
||||
List<CarType> carTypes = [
|
||||
CarType(
|
||||
carType: 'Speed',
|
||||
@@ -49,10 +49,6 @@ List<CarType> carTypes = [
|
||||
carType: 'Van',
|
||||
carDetail: 'Van for familly'.tr,
|
||||
image: 'assets/images/bus.png'),
|
||||
// CarType(
|
||||
// carType: 'Scooter',
|
||||
// carDetail: 'Delivery service'.tr,
|
||||
// image: 'assets/images/moto.png'),
|
||||
CarType(
|
||||
carType: 'Rayeh Gai',
|
||||
carDetail: "Best choice for cities".tr,
|
||||
@@ -65,6 +61,7 @@ class CarDetailsTypeToChoose extends StatelessWidget {
|
||||
final textToSpeechController = Get.put(TextToSpeechController());
|
||||
|
||||
void _prepareCarTypes(MapPassengerController controller) {
|
||||
// This logic remains the same
|
||||
if (controller.distance > 33) {
|
||||
if (!carTypes.any((car) => car.carType == 'Rayeh Gai')) {
|
||||
carTypes.add(CarType(
|
||||
@@ -87,56 +84,69 @@ class CarDetailsTypeToChoose extends StatelessWidget {
|
||||
controller.rideConfirm == false)) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
// Added a BackdropFilter for a modern glassmorphism effect
|
||||
return Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.secondaryColor,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(24),
|
||||
topRight: Radius.circular(24),
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.2),
|
||||
blurRadius: 20,
|
||||
spreadRadius: 5,
|
||||
),
|
||||
],
|
||||
child: ClipRRect(
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(30),
|
||||
topRight: Radius.circular(30),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildHeader(controller),
|
||||
const Divider(height: 1),
|
||||
_buildNegativeBalanceWarning(controller),
|
||||
SizedBox(
|
||||
height: 130,
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
itemCount: carTypes.length,
|
||||
itemBuilder: (context, index) {
|
||||
final carType = carTypes[index];
|
||||
final isSelected = controller.selectedIndex == index;
|
||||
return _buildHorizontalCarCard(
|
||||
context, controller, carType, isSelected, index);
|
||||
},
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.secondaryColor.withOpacity(0.9),
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(30),
|
||||
topRight: Radius.circular(30),
|
||||
),
|
||||
border: Border.all(color: AppColor.writeColor.withOpacity(0.1)),
|
||||
),
|
||||
_buildPromoButton(context, controller),
|
||||
],
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Added a small handle for visual cue
|
||||
Container(
|
||||
width: 40,
|
||||
height: 5,
|
||||
margin: const EdgeInsets.symmetric(vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.writeColor.withOpacity(0.3),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
_buildHeader(controller),
|
||||
_buildNegativeBalanceWarning(controller),
|
||||
SizedBox(
|
||||
height: 140, // Increased height for better spacing
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20, vertical: 12),
|
||||
itemCount: carTypes.length,
|
||||
itemBuilder: (context, index) {
|
||||
final carType = carTypes[index];
|
||||
final isSelected = controller.selectedIndex == index;
|
||||
return _buildHorizontalCarCard(
|
||||
context, controller, carType, isSelected, index);
|
||||
},
|
||||
),
|
||||
),
|
||||
_buildPromoButton(context, controller),
|
||||
const SizedBox(height: 8), // Added padding at the bottom
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// --- All other methods are here, with updates for 'Electric' car ---
|
||||
// --- All other methods are here, with updated designs ---
|
||||
|
||||
Widget _buildPromoButton(
|
||||
BuildContext context, MapPassengerController controller) {
|
||||
@@ -145,32 +155,34 @@ class CarDetailsTypeToChoose extends StatelessWidget {
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
child: OutlinedButton(
|
||||
onPressed: () => _showPromoCodeDialog(context, controller),
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.fromLTRB(20, 0, 20, 16),
|
||||
child: GestureDetector(
|
||||
onTap: () => _showPromoCodeDialog(context, controller),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
backgroundColor: AppColor.primaryColor.withOpacity(0.05),
|
||||
side: BorderSide(
|
||||
color: AppColor.primaryColor.withOpacity(0.7),
|
||||
width: 1.5,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.local_offer_outlined,
|
||||
color: AppColor.primaryColor, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Have a promo code?'.tr,
|
||||
style: AppStyle.title
|
||||
.copyWith(fontSize: 16, color: AppColor.primaryColor),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.primaryColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: AppColor.primaryColor.withOpacity(0.5),
|
||||
width: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.local_offer_outlined,
|
||||
color: AppColor.primaryColor, size: 22),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'Have a promo code?'.tr,
|
||||
style: AppStyle.title.copyWith(
|
||||
fontSize: 16,
|
||||
color: AppColor.primaryColor,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -263,35 +275,55 @@ class CarDetailsTypeToChoose extends StatelessWidget {
|
||||
_showCarDetailsDialog(
|
||||
context, controller, carType, textToSpeechController);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
width: 110,
|
||||
width: 120, // Increased width
|
||||
margin: const EdgeInsets.only(right: 12),
|
||||
padding: const EdgeInsets.all(8), // Added padding
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? AppColor.primaryColor.withOpacity(0.15)
|
||||
: AppColor.writeColor.withOpacity(0.05),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: isSelected ? AppColor.primaryColor : Colors.transparent,
|
||||
width: 2.0,
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: isSelected
|
||||
? [
|
||||
AppColor.primaryColor.withOpacity(0.3),
|
||||
AppColor.primaryColor.withOpacity(0.1)
|
||||
]
|
||||
: [
|
||||
AppColor.writeColor.withOpacity(0.05),
|
||||
AppColor.writeColor.withOpacity(0.1)
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(20), // More rounded corners
|
||||
border: Border.all(
|
||||
color: isSelected
|
||||
? AppColor.primaryColor
|
||||
: AppColor.writeColor.withOpacity(0.2),
|
||||
width: isSelected ? 2.5 : 1.0,
|
||||
),
|
||||
boxShadow: isSelected
|
||||
? [
|
||||
BoxShadow(
|
||||
color: AppColor.primaryColor.withOpacity(0.3),
|
||||
blurRadius: 10,
|
||||
spreadRadius: 1,
|
||||
)
|
||||
]
|
||||
: [],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround, // Better alignment
|
||||
children: [
|
||||
Image.asset(carType.image, height: 50),
|
||||
const SizedBox(height: 8),
|
||||
Image.asset(carType.image, height: 55), // Slightly larger image
|
||||
Text(
|
||||
carType.carType.tr,
|
||||
style: AppStyle.subtitle
|
||||
.copyWith(fontWeight: FontWeight.bold, fontSize: 14),
|
||||
.copyWith(fontWeight: FontWeight.bold, fontSize: 15),
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
_buildPriceDisplay(controller, carType),
|
||||
],
|
||||
),
|
||||
@@ -301,20 +333,44 @@ class CarDetailsTypeToChoose extends StatelessWidget {
|
||||
|
||||
Widget _buildHeader(MapPassengerController controller) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 12),
|
||||
padding: const EdgeInsets.fromLTRB(20, 8, 20, 16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Choose your ride'.tr,
|
||||
style: AppStyle.headTitle.copyWith(fontSize: 22)),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${controller.distance} ${'KM'.tr} • ${controller.hours > 0 ? '${controller.hours}h ${controller.minutes}m' : '${controller.minutes} min'}',
|
||||
style: AppStyle.subtitle.copyWith(
|
||||
color: AppColor.primaryColor, fontWeight: FontWeight.bold),
|
||||
style: AppStyle.headTitle.copyWith(fontSize: 24)),
|
||||
const SizedBox(height: 8),
|
||||
// Added icons for better visual representation
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.map_outlined,
|
||||
color: AppColor.primaryColor, size: 16),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'${controller.distance} ${'KM'.tr}',
|
||||
style: AppStyle.subtitle.copyWith(
|
||||
color: AppColor.primaryColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Icon(Icons.timer_outlined,
|
||||
color: AppColor.primaryColor, size: 16),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
controller.hours > 0
|
||||
? '${controller.hours}h ${controller.minutes}m'
|
||||
: '${controller.minutes} min',
|
||||
style: AppStyle.subtitle.copyWith(
|
||||
color: AppColor.primaryColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -328,8 +384,12 @@ class CarDetailsTypeToChoose extends StatelessWidget {
|
||||
double.tryParse(box.read(BoxName.passengerWalletTotal) ?? '0.0') ?? 0.0;
|
||||
if (passengerWallet < 0.0) {
|
||||
return Container(
|
||||
color: AppColor.redColor.withOpacity(0.8),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.redColor.withOpacity(0.9),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.error_outline, color: Colors.white, size: 24),
|
||||
@@ -337,7 +397,8 @@ class CarDetailsTypeToChoose extends StatelessWidget {
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${'You have a negative balance of'.tr} ${passengerWallet.toStringAsFixed(2)} ${'SYP'.tr}.',
|
||||
style: AppStyle.subtitle.copyWith(color: Colors.white))),
|
||||
style: AppStyle.subtitle.copyWith(
|
||||
color: Colors.white, fontWeight: FontWeight.w600))),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -350,12 +411,13 @@ class CarDetailsTypeToChoose extends StatelessWidget {
|
||||
return Text(
|
||||
'${_getPassengerPriceText(carType, mapPassengerController)} ${'SYP'.tr}',
|
||||
style: AppStyle.subtitle.copyWith(
|
||||
fontSize: 14,
|
||||
fontSize: 15, // Increased font size
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColor.primaryColor));
|
||||
}
|
||||
|
||||
// UPDATED to include 'Electric'
|
||||
// --- LOGIC METHODS (UNCHANGED) ---
|
||||
|
||||
String _getPassengerPriceText(
|
||||
CarType carType, MapPassengerController mapPassengerController) {
|
||||
switch (carType.carType) {
|
||||
@@ -391,79 +453,97 @@ class CarDetailsTypeToChoose extends StatelessWidget {
|
||||
Dialog(
|
||||
shape:
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(24.0)),
|
||||
backgroundColor: AppColor.secondaryColor,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 24, 20, 20),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Image.asset(carType.image, height: 70),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
carType.carType.tr,
|
||||
style: AppStyle.headTitle.copyWith(fontSize: 22),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
onPressed: () => textToSpeechController.speakText(
|
||||
_getCarDescription(mapPassengerController, carType)),
|
||||
icon: Icon(Icons.volume_up_outlined,
|
||||
color: AppColor.primaryColor, size: 24),
|
||||
),
|
||||
],
|
||||
backgroundColor:
|
||||
Colors.transparent, // Make dialog background transparent
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
alignment: Alignment.topCenter,
|
||||
children: [
|
||||
// Main content container
|
||||
Container(
|
||||
margin:
|
||||
const EdgeInsets.only(top: 50), // Make space for the image
|
||||
padding: const EdgeInsets.fromLTRB(20, 70, 20, 20),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColor.secondaryColor,
|
||||
borderRadius: BorderRadius.circular(24.0),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
_getCarDescription(mapPassengerController, carType),
|
||||
textAlign: TextAlign.center,
|
||||
style: AppStyle.subtitle.copyWith(
|
||||
color: AppColor.writeColor.withOpacity(0.7),
|
||||
fontSize: 15,
|
||||
height: 1.4,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextButton(
|
||||
onPressed: () => Get.back(),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColor.writeColor.withOpacity(0.8),
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
carType.carType.tr,
|
||||
style: AppStyle.headTitle.copyWith(fontSize: 24),
|
||||
),
|
||||
child: Text('Cancel'.tr),
|
||||
const SizedBox(width: 8),
|
||||
IconButton(
|
||||
onPressed: () => textToSpeechController.speakText(
|
||||
_getCarDescription(
|
||||
mapPassengerController, carType)),
|
||||
icon: Icon(Icons.volume_up_outlined,
|
||||
color: AppColor.primaryColor, size: 26),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
_getCarDescription(mapPassengerController, carType),
|
||||
textAlign: TextAlign.center,
|
||||
style: AppStyle.subtitle.copyWith(
|
||||
color: AppColor.writeColor.withOpacity(0.7),
|
||||
fontSize: 16,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: MyElevatedButton(
|
||||
kolor: AppColor.greenColor,
|
||||
title: 'Next'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
_handleCarSelection(
|
||||
context, mapPassengerController, carType);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 28),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextButton(
|
||||
onPressed: () => Get.back(),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor:
|
||||
AppColor.writeColor.withOpacity(0.8),
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
child: Text('Cancel'.tr),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: MyElevatedButton(
|
||||
kolor: AppColor.greenColor,
|
||||
title: 'Next'.tr,
|
||||
onPressed: () {
|
||||
Get.back();
|
||||
_handleCarSelection(
|
||||
context, mapPassengerController, carType);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Positioned car image
|
||||
Positioned(
|
||||
top: -10,
|
||||
child: Image.asset(carType.image, height: 120),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
barrierColor: Colors.black.withOpacity(0.5),
|
||||
barrierColor: Colors.black.withOpacity(0.6),
|
||||
);
|
||||
}
|
||||
|
||||
// UPDATED to include 'Electric'
|
||||
String _getCarDescription(
|
||||
MapPassengerController mapPassengerController, CarType carType) {
|
||||
switch (carType.carType) {
|
||||
@@ -553,7 +633,6 @@ class CarDetailsTypeToChoose extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// UPDATED to include 'Electric'
|
||||
double _getOriginalPrice(
|
||||
CarType carType, MapPassengerController mapPassengerController) {
|
||||
switch (carType.carType) {
|
||||
@@ -595,6 +674,7 @@ class CarDetailsTypeToChoose extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// --- BurcMoney Widget (Unchanged) ---
|
||||
class BurcMoney extends StatelessWidget {
|
||||
const BurcMoney({super.key});
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
@@ -11,123 +13,232 @@ import '../../../controller/functions/toast.dart';
|
||||
import '../../../controller/home/map_passenger_controller.dart';
|
||||
import '../../../main.dart';
|
||||
|
||||
// ---------------------------------------------------
|
||||
// -- Widget for Destination Point Search (Optimized) --
|
||||
// ---------------------------------------------------
|
||||
|
||||
/// A more optimized and cleaner implementation of the destination search form.
|
||||
///
|
||||
/// Improvements:
|
||||
/// 1. **Widget Refactoring**: The UI is broken down into smaller, focused widgets
|
||||
/// (_SearchField, _QuickActions, _SearchResults) to prevent unnecessary rebuilds.
|
||||
/// 2. **State Management Scoping**: `GetBuilder` is used only on widgets that
|
||||
/// actually need to update, not the entire form.
|
||||
/// 3. **Reduced Build Logic**: Logic like reading from `box` is done once.
|
||||
/// 4. **Readability**: Code is cleaner and easier to follow.
|
||||
GetBuilder<MapPassengerController> formSearchPlacesDestenation() {
|
||||
if (box.read(BoxName.addWork).toString() == '' ||
|
||||
box.read(BoxName.addHome).toString() == '') {
|
||||
// --- [تحسين] قراءة القيم مرة واحدة في بداية البناء ---
|
||||
// Store box values in local variables to avoid repeated calls inside the build method.
|
||||
final String addWorkValue =
|
||||
box.read(BoxName.addWork)?.toString() ?? 'addWork';
|
||||
final String addHomeValue =
|
||||
box.read(BoxName.addHome)?.toString() ?? 'addHome';
|
||||
|
||||
// --- [ملاحظة] تأكد من أن القيم الأولية موجودة ---
|
||||
// This initialization can be moved to your app's startup logic or a splash screen controller.
|
||||
if (addWorkValue.isEmpty || addHomeValue.isEmpty) {
|
||||
box.write(BoxName.addWork, 'addWork');
|
||||
box.write(BoxName.addHome, 'addHome');
|
||||
}
|
||||
|
||||
return GetBuilder<MapPassengerController>(
|
||||
builder: (controller) => Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: controller.placeDestinationController,
|
||||
onChanged: (value) {
|
||||
if (controller.placeDestinationController.text.length > 2) {
|
||||
controller.getPlaces();
|
||||
controller.changeHeightPlaces();
|
||||
} else if (controller
|
||||
.placeDestinationController.text.isEmpty) {
|
||||
controller.clearPlacesDestination();
|
||||
controller.changeHeightPlaces();
|
||||
}
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: controller.hintTextDestinationPoint,
|
||||
hintStyle:
|
||||
AppStyle.subtitle.copyWith(color: Colors.grey[600]),
|
||||
prefixIcon:
|
||||
const Icon(Icons.search, color: AppColor.primaryColor),
|
||||
suffixIcon: controller
|
||||
.placeDestinationController.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: Icon(Icons.clear, color: Colors.grey[400]),
|
||||
onPressed: () {
|
||||
controller.placeDestinationController.clear();
|
||||
controller.clearPlacesDestination();
|
||||
controller.changeHeightPlaces();
|
||||
},
|
||||
)
|
||||
: null,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0, vertical: 10.0),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide(color: AppColor.primaryColor),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Colors.grey[50],
|
||||
),
|
||||
id: 'destination_form', // Use an ID to allow targeted updates
|
||||
builder: (controller) {
|
||||
return Column(
|
||||
children: [
|
||||
// --- Widget for the search text field ---
|
||||
_SearchField(controller: controller),
|
||||
|
||||
// --- Widget for "Add Work" and "Add Home" buttons ---
|
||||
_QuickActions(
|
||||
controller: controller,
|
||||
addWorkValue: addWorkValue,
|
||||
addHomeValue: addHomeValue,
|
||||
),
|
||||
|
||||
// --- Widget for displaying search results, wrapped in its own GetBuilder ---
|
||||
_SearchResults(),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// -- Private Helper Widgets for Cleaner Code --
|
||||
// ---------------------------------------------------
|
||||
|
||||
/// A dedicated widget for the search input field.
|
||||
class _SearchField extends StatefulWidget {
|
||||
final MapPassengerController controller;
|
||||
|
||||
const _SearchField({required this.controller});
|
||||
|
||||
@override
|
||||
State<_SearchField> createState() => _SearchFieldState();
|
||||
}
|
||||
|
||||
class _SearchFieldState extends State<_SearchField> {
|
||||
Timer? _debounce;
|
||||
|
||||
// --- [إصلاح] Listener لتحديث الواجهة عند تغيير النص لإظهار/إخفاء زر المسح ---
|
||||
void _onTextChanged() {
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Add listener to update the suffix icon when text changes
|
||||
widget.controller.placeDestinationController.addListener(_onTextChanged);
|
||||
}
|
||||
|
||||
// --- [تحسين] إضافة Debouncer لتأخير البحث أثناء الكتابة ---
|
||||
void _onSearchChanged(String query) {
|
||||
if (_debounce?.isActive ?? false) _debounce!.cancel();
|
||||
_debounce = Timer(const Duration(milliseconds: 500), () {
|
||||
if (query.length > 2) {
|
||||
widget.controller.getPlaces();
|
||||
widget.controller.changeHeightPlaces();
|
||||
} else if (query.isEmpty) {
|
||||
widget.controller.clearPlacesDestination();
|
||||
widget.controller.changeHeightPlaces();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_debounce?.cancel();
|
||||
// Remove the listener to prevent memory leaks
|
||||
widget.controller.placeDestinationController.removeListener(_onTextChanged);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: widget.controller.placeDestinationController,
|
||||
onChanged: _onSearchChanged,
|
||||
decoration: InputDecoration(
|
||||
hintText: widget.controller.hintTextDestinationPoint,
|
||||
hintStyle: AppStyle.subtitle.copyWith(color: Colors.grey[600]),
|
||||
prefixIcon:
|
||||
const Icon(Icons.search, color: AppColor.primaryColor),
|
||||
// --- [إصلاح] تم استبدال Obx بشرط بسيط لأن `setState` يعيد بناء الواجهة الآن ---
|
||||
suffixIcon: widget
|
||||
.controller.placeDestinationController.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: Icon(Icons.clear, color: Colors.grey[400]),
|
||||
onPressed: () {
|
||||
widget.controller.placeDestinationController.clear();
|
||||
// The listener will automatically handle the UI update
|
||||
// And _onSearchChanged will handle clearing the results
|
||||
},
|
||||
)
|
||||
: null, // Use null instead of SizedBox for better practice
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0, vertical: 10.0),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide(color: AppColor.primaryColor),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Colors.grey[50],
|
||||
),
|
||||
const SizedBox(width: 8.0),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
controller.changeMainBottomMenuMap();
|
||||
controller.changePickerShown();
|
||||
},
|
||||
icon: Icon(Icons.location_on_outlined,
|
||||
color: AppColor.accentColor, size: 30),
|
||||
tooltip: controller.isAnotherOreder
|
||||
? 'Pick destination on map'
|
||||
: 'Pick on map',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildQuickActionButton(
|
||||
icon: Icons.work_outline,
|
||||
text: box.read(BoxName.addWork) == 'addWork'
|
||||
? 'Add Work'.tr
|
||||
: 'To Work'.tr,
|
||||
onTap: () async {
|
||||
if (box.read(BoxName.addWork) == 'addWork') {
|
||||
controller.workLocationFromMap = true;
|
||||
controller.changeMainBottomMenuMap();
|
||||
controller.changePickerShown();
|
||||
} else {
|
||||
_handleQuickAction(controller, BoxName.addWork, 'To Work');
|
||||
}
|
||||
},
|
||||
onLongPress: () =>
|
||||
_showChangeLocationDialog(controller, 'Work'),
|
||||
),
|
||||
_buildQuickActionButton(
|
||||
icon: Icons.home_outlined,
|
||||
text: box.read(BoxName.addHome) == 'addHome'
|
||||
? 'Add Home'.tr
|
||||
: 'To Home'.tr,
|
||||
onTap: () async {
|
||||
if (box.read(BoxName.addHome) == 'addHome') {
|
||||
controller.homeLocationFromMap = true;
|
||||
controller.changeMainBottomMenuMap();
|
||||
controller.changePickerShown();
|
||||
} else {
|
||||
_handleQuickAction(controller, BoxName.addHome, 'To Home');
|
||||
}
|
||||
},
|
||||
onLongPress: () =>
|
||||
_showChangeLocationDialog(controller, 'Home'),
|
||||
),
|
||||
],
|
||||
const SizedBox(width: 8.0),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
widget.controller.changeMainBottomMenuMap();
|
||||
widget.controller.changePickerShown();
|
||||
},
|
||||
icon: Icon(Icons.location_on_outlined,
|
||||
color: AppColor.accentColor, size: 30),
|
||||
tooltip: widget.controller.isAnotherOreder
|
||||
? 'Pick destination on map'
|
||||
: 'Pick on map',
|
||||
),
|
||||
),
|
||||
AnimatedContainer(
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A dedicated widget for the quick action buttons (Work/Home).
|
||||
class _QuickActions extends StatelessWidget {
|
||||
final MapPassengerController controller;
|
||||
final String addWorkValue;
|
||||
final String addHomeValue;
|
||||
|
||||
const _QuickActions({
|
||||
required this.controller,
|
||||
required this.addWorkValue,
|
||||
required this.addHomeValue,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildQuickActionButton(
|
||||
icon: Icons.work_outline,
|
||||
text: addWorkValue == 'addWork' ? 'Add Work'.tr : 'To Work'.tr,
|
||||
onTap: () {
|
||||
if (addWorkValue == 'addWork') {
|
||||
controller.workLocationFromMap = true;
|
||||
controller.changeMainBottomMenuMap();
|
||||
controller.changePickerShown();
|
||||
} else {
|
||||
_handleQuickAction(controller, BoxName.addWork, 'To Work');
|
||||
}
|
||||
},
|
||||
onLongPress: () => _showChangeLocationDialog(controller, 'Work'),
|
||||
),
|
||||
_buildQuickActionButton(
|
||||
icon: Icons.home_outlined,
|
||||
text: addHomeValue == 'addHome' ? 'Add Home'.tr : 'To Home'.tr,
|
||||
onTap: () {
|
||||
if (addHomeValue == 'addHome') {
|
||||
controller.homeLocationFromMap = true;
|
||||
controller.changeMainBottomMenuMap();
|
||||
controller.changePickerShown();
|
||||
} else {
|
||||
_handleQuickAction(controller, BoxName.addHome, 'To Home');
|
||||
}
|
||||
},
|
||||
onLongPress: () => _showChangeLocationDialog(controller, 'Home'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A dedicated widget for the search results list.
|
||||
/// It uses its own `GetBuilder` to only rebuild when the list of places changes.
|
||||
class _SearchResults extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GetBuilder<MapPassengerController>(
|
||||
id: 'places_list', // Use a specific ID for targeted updates
|
||||
builder: (controller) {
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
height: controller.placesDestination.isNotEmpty ? 300 : 0,
|
||||
decoration: BoxDecoration(
|
||||
@@ -137,20 +248,16 @@ GetBuilder<MapPassengerController> formSearchPlacesDestenation() {
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
physics: const ClampingScrollPhysics(),
|
||||
itemCount: controller.placesDestination.length,
|
||||
separatorBuilder: (context, index) =>
|
||||
const Divider(height: 1, color: Colors.grey),
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
var res = controller.placesDestination[index];
|
||||
|
||||
// استخراج البيانات حسب بنية السيرفر الجديد
|
||||
var title = res['name'] ?? 'Unknown Place';
|
||||
var address = res['address'] ?? 'Unknown Address';
|
||||
var latitude = res['latitude'];
|
||||
var longitude = res['longitude'];
|
||||
var primaryCategory =
|
||||
'Place'; // يمكن تطويره لاحقاً لو أضفت نوع للمكان
|
||||
final res = controller.placesDestination[index];
|
||||
final title = res['name_ar'] ?? res['name'] ?? 'Unknown Place';
|
||||
final address = res['address'] ?? 'Details not available';
|
||||
final latitude = res['latitude'];
|
||||
final longitude = res['longitude'];
|
||||
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.place, size: 30, color: Colors.grey),
|
||||
@@ -165,65 +272,105 @@ GetBuilder<MapPassengerController> formSearchPlacesDestenation() {
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.favorite_border, color: Colors.grey),
|
||||
onPressed: () async {
|
||||
if (latitude != null && longitude != null) {
|
||||
await sql.insertMapLocation({
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'name': title,
|
||||
'rate': 'N/A',
|
||||
}, TableName.placesFavorite);
|
||||
|
||||
Toast.show(
|
||||
context,
|
||||
'$title ${'Saved Successfully'.tr}',
|
||||
AppColor.primaryColor,
|
||||
);
|
||||
} else {
|
||||
Toast.show(
|
||||
context,
|
||||
'Invalid location data',
|
||||
AppColor.redColor,
|
||||
);
|
||||
}
|
||||
},
|
||||
onPressed: () => _handleAddToFavorites(
|
||||
context, latitude, longitude, title),
|
||||
),
|
||||
onTap: () async {
|
||||
if (latitude != null && longitude != null) {
|
||||
await sql.insertMapLocation({
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'name': title,
|
||||
'rate': 'N/A',
|
||||
'createdAt': DateTime.now().toIso8601String(),
|
||||
}, TableName.recentLocations);
|
||||
|
||||
controller.passengerLocation = controller.newMyLocation;
|
||||
controller.myDestination = LatLng(latitude, longitude);
|
||||
controller.convertHintTextDestinationNewPlaces(index);
|
||||
|
||||
controller.placesDestination = [];
|
||||
controller.placeDestinationController.clear();
|
||||
controller.changeMainBottomMenuMap();
|
||||
controller.passengerStartLocationFromMap = true;
|
||||
controller.isPickerShown = true;
|
||||
} else {
|
||||
Toast.show(
|
||||
context,
|
||||
'Invalid location data',
|
||||
AppColor.redColor,
|
||||
);
|
||||
}
|
||||
},
|
||||
onTap: () => _handlePlaceSelection(
|
||||
controller, latitude, longitude, title, index),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// --- [تحسين] استخراج المنطق المعقد إلى دوال مساعدة ---
|
||||
Future<void> _handleAddToFavorites(BuildContext context, dynamic latitude,
|
||||
dynamic longitude, String title) async {
|
||||
if (latitude != null && longitude != null) {
|
||||
await sql.insertMapLocation({
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'name': title,
|
||||
'rate': 'N/A',
|
||||
}, TableName.placesFavorite);
|
||||
|
||||
Toast.show(
|
||||
context,
|
||||
'$title ${'Saved Successfully'.tr}',
|
||||
AppColor.primaryColor,
|
||||
);
|
||||
} else {
|
||||
Toast.show(
|
||||
context,
|
||||
'Invalid location data',
|
||||
AppColor.redColor,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handlePlaceSelection(MapPassengerController controller,
|
||||
dynamic latitude, dynamic longitude, String title, int index) async {
|
||||
if (latitude == null || longitude == null) {
|
||||
Toast.show(Get.context!, 'Invalid location data', AppColor.redColor);
|
||||
return;
|
||||
}
|
||||
|
||||
// Save to recent locations
|
||||
await sql.insertMapLocation({
|
||||
'latitude': latitude,
|
||||
'longitude': longitude,
|
||||
'name': title,
|
||||
'rate': 'N/A',
|
||||
'createdAt': DateTime.now().toIso8601String(),
|
||||
}, TableName.recentLocations);
|
||||
|
||||
final destLatLng = LatLng(
|
||||
double.parse(latitude.toString()), double.parse(longitude.toString()));
|
||||
|
||||
if (controller.isAnotherOreder) {
|
||||
// **Another Order Flow**
|
||||
await _handleAnotherOrderSelection(controller, destLatLng);
|
||||
} else {
|
||||
// **Regular Order Flow**
|
||||
_handleRegularOrderSelection(controller, destLatLng, index);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _handleAnotherOrderSelection(
|
||||
MapPassengerController controller, LatLng destination) async {
|
||||
controller.myDestination = destination;
|
||||
controller.clearPlacesDestination(); // Helper method in controller
|
||||
|
||||
await controller.getDirectionMap(
|
||||
'${controller.passengerLocation.latitude},${controller.passengerLocation.longitude}',
|
||||
'${controller.myDestination.latitude},${controller.myDestination.longitude}');
|
||||
|
||||
controller.isPickerShown = false;
|
||||
controller.passengerStartLocationFromMap = false;
|
||||
controller.changeMainBottomMenuMap();
|
||||
controller.showBottomSheet1();
|
||||
}
|
||||
|
||||
void _handleRegularOrderSelection(
|
||||
MapPassengerController controller, LatLng destination, int index) {
|
||||
controller.passengerLocation = controller.newMyLocation;
|
||||
controller.myDestination = destination;
|
||||
controller.convertHintTextDestinationNewPlaces(index);
|
||||
|
||||
controller.clearPlacesDestination(); // Helper method in controller
|
||||
|
||||
controller.changeMainBottomMenuMap();
|
||||
controller.passengerStartLocationFromMap = true;
|
||||
controller.isPickerShown = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
// -- Helper Functions (kept from original code) --
|
||||
// ---------------------------------------------------
|
||||
|
||||
Widget _buildQuickActionButton({
|
||||
required IconData icon,
|
||||
required String text,
|
||||
@@ -280,22 +427,31 @@ void _showChangeLocationDialog(
|
||||
|
||||
void _handleQuickAction(
|
||||
MapPassengerController controller, String boxName, String hintText) async {
|
||||
final latLng = LatLng(
|
||||
double.parse(box.read(boxName).toString().split(',')[0]),
|
||||
double.parse(box.read(boxName).toString().split(',')[1]),
|
||||
);
|
||||
controller.hintTextDestinationPoint = hintText;
|
||||
controller.changeMainBottomMenuMap();
|
||||
// --- [تحسين] قراءة وتحويل الإحداثيات بأمان أكبر ---
|
||||
try {
|
||||
final locationString = box.read(boxName).toString();
|
||||
final parts = locationString.split(',');
|
||||
final latLng = LatLng(
|
||||
double.parse(parts[0]),
|
||||
double.parse(parts[1]),
|
||||
);
|
||||
|
||||
await controller.getDirectionMap(
|
||||
'${controller.passengerLocation.latitude},${controller.passengerLocation.longitude}',
|
||||
'${latLng.latitude},${latLng.longitude}',
|
||||
);
|
||||
controller.currentLocationToFormPlaces = false;
|
||||
controller.placesDestination = [];
|
||||
controller.clearPlacesStart();
|
||||
controller.clearPlacesDestination();
|
||||
controller.passengerStartLocationFromMap = false;
|
||||
controller.isPickerShown = false;
|
||||
controller.showBottomSheet1();
|
||||
controller.hintTextDestinationPoint = hintText;
|
||||
controller.changeMainBottomMenuMap();
|
||||
|
||||
await controller.getDirectionMap(
|
||||
'${controller.passengerLocation.latitude},${controller.passengerLocation.longitude}',
|
||||
'${latLng.latitude},${latLng.longitude}',
|
||||
);
|
||||
|
||||
controller.currentLocationToFormPlaces = false;
|
||||
controller.clearPlacesDestination(); // Helper method in controller
|
||||
controller.passengerStartLocationFromMap = false;
|
||||
controller.isPickerShown = false;
|
||||
controller.showBottomSheet1();
|
||||
} catch (e) {
|
||||
// Handle error if parsing fails
|
||||
print("Error handling quick action: $e");
|
||||
Toast.show(Get.context!, "Failed to get location".tr, AppColor.redColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:Intaleq/constant/table_names.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
|
||||
import '../../../constant/colors.dart';
|
||||
import '../../../constant/style.dart';
|
||||
import '../../../controller/functions/toast.dart';
|
||||
import '../../../controller/home/map_passenger_controller.dart';
|
||||
import '../../../main.dart';
|
||||
|
||||
// ---------------------------------------------------
|
||||
// -- Widget for Start Point Search --
|
||||
// ---------------------------------------------------
|
||||
|
||||
GetBuilder<MapPassengerController> formSearchPlacesStart() {
|
||||
return GetBuilder<MapPassengerController>(
|
||||
@@ -14,70 +16,47 @@ GetBuilder<MapPassengerController> formSearchPlacesStart() {
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextFormField(
|
||||
controller: controller.placeStartController,
|
||||
onChanged: (value) {
|
||||
if (controller.placeStartController.text.length > 5) {
|
||||
// Reduced character limit
|
||||
controller.getPlacesStart();
|
||||
controller.changeHeightStartPlaces();
|
||||
} else if (controller.placeStartController.text.isEmpty) {
|
||||
controller.clearPlacesStart();
|
||||
controller.changeHeightPlaces(); // Collapse if empty
|
||||
}
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: controller.hintTextStartPoint,
|
||||
hintStyle:
|
||||
AppStyle.subtitle.copyWith(color: Colors.grey[600]),
|
||||
prefixIcon:
|
||||
const Icon(Icons.search, color: AppColor.primaryColor),
|
||||
suffixIcon: controller.placeStartController.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: Icon(Icons.clear, color: Colors.grey[400]),
|
||||
onPressed: () {
|
||||
controller.placeStartController.clear();
|
||||
controller.clearPlacesStart();
|
||||
controller
|
||||
.changeHeightPlaces(); // Collapse on clear
|
||||
},
|
||||
)
|
||||
: null,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0, vertical: 10.0),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide(color: AppColor.primaryColor),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Colors.grey[50],
|
||||
),
|
||||
),
|
||||
child: TextFormField(
|
||||
controller: controller.placeStartController,
|
||||
onChanged: (value) {
|
||||
if (controller.placeStartController.text.length > 2) {
|
||||
controller.getPlacesStart();
|
||||
} else if (controller.placeStartController.text.isEmpty) {
|
||||
controller.clearPlacesStart();
|
||||
}
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Search for a starting point'.tr,
|
||||
hintStyle: AppStyle.subtitle.copyWith(color: Colors.grey[600]),
|
||||
prefixIcon:
|
||||
const Icon(Icons.search, color: AppColor.primaryColor),
|
||||
suffixIcon: controller.placeStartController.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: Icon(Icons.clear, color: Colors.grey[400]),
|
||||
onPressed: () {
|
||||
controller.placeStartController.clear();
|
||||
controller.clearPlacesStart();
|
||||
},
|
||||
)
|
||||
: null,
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
const SizedBox(width: 8.0),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
controller.startLocationFromMap = true;
|
||||
controller.changeMainBottomMenuMap();
|
||||
controller.changePickerShown();
|
||||
},
|
||||
icon: Icon(Icons.location_on_outlined,
|
||||
color: AppColor.accentColor, size: 30),
|
||||
tooltip: 'Choose on Map',
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
borderSide: BorderSide(color: AppColor.primaryColor),
|
||||
),
|
||||
],
|
||||
filled: true,
|
||||
fillColor: Colors.grey[50],
|
||||
),
|
||||
),
|
||||
),
|
||||
AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
height: controller.placesStart.isNotEmpty ? controller.height : 0,
|
||||
height: controller.placesStart.isNotEmpty ? 300 : 0,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
@@ -85,48 +64,33 @@ GetBuilder<MapPassengerController> formSearchPlacesStart() {
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||
child: ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
physics: const ClampingScrollPhysics(),
|
||||
itemCount: controller.placesStart.length,
|
||||
separatorBuilder: (context, index) =>
|
||||
const Divider(height: 1, color: Colors.grey),
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
var res = controller.placesStart[index];
|
||||
var title = res['name_ar'] ?? res['name'] ?? 'Unknown Place';
|
||||
var address = res['address'] ?? 'Details not available';
|
||||
|
||||
return ListTile(
|
||||
leading: Image.network(res['icon'], width: 30, height: 30),
|
||||
title: Text(res['name'].toString(),
|
||||
leading: const Icon(Icons.place, size: 30, color: Colors.grey),
|
||||
title: Text(title,
|
||||
style: AppStyle.subtitle
|
||||
.copyWith(fontWeight: FontWeight.w500)),
|
||||
subtitle: Text(res['vicinity'].toString(),
|
||||
subtitle: Text(address,
|
||||
style: TextStyle(color: Colors.grey[600], fontSize: 12)),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.favorite_border, color: Colors.grey),
|
||||
onPressed: () async {
|
||||
await sql.insertMapLocation({
|
||||
'latitude': res['geometry']['location']['lat'],
|
||||
'longitude': res['geometry']['location']['lng'],
|
||||
'name': res['name'].toString(),
|
||||
'rate': res['rating'].toString(),
|
||||
}, TableName.placesFavorite);
|
||||
Toast.show(
|
||||
context,
|
||||
'${res['name']} ${'Saved Successfully'.tr}',
|
||||
AppColor.primaryColor);
|
||||
},
|
||||
),
|
||||
onTap: () async {
|
||||
controller.changeHeightPlaces();
|
||||
await sql.insertMapLocation({
|
||||
'latitude': res['geometry']['location']['lat'],
|
||||
'longitude': res['geometry']['location']['lng'],
|
||||
'name': res['name'].toString(),
|
||||
'rate': res['rating'].toString(),
|
||||
'createdAt': DateTime.now().toIso8601String(),
|
||||
}, TableName.recentLocations);
|
||||
|
||||
controller.convertHintTextStartNewPlaces(index);
|
||||
controller.currentLocationString = res['name'];
|
||||
controller.placesStart = [];
|
||||
controller.placeStartController.clear();
|
||||
onTap: () {
|
||||
var latitude = res['latitude'];
|
||||
var longitude = res['longitude'];
|
||||
if (latitude != null && longitude != null) {
|
||||
controller.passengerLocation =
|
||||
LatLng(double.parse(latitude), double.parse(longitude));
|
||||
controller.placeStartController.text = title;
|
||||
controller.clearPlacesStart();
|
||||
// You might want to update the camera position on the map here
|
||||
controller.update();
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import 'package:Intaleq/constant/box_name.dart';
|
||||
import 'package:Intaleq/controller/firebase/firbase_messge.dart';
|
||||
import 'package:Intaleq/controller/firebase/notification_service.dart';
|
||||
import 'package:Intaleq/main.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_font_icons/flutter_font_icons.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -6,9 +9,12 @@ import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'dart:ui'; // مهم لإضافة تأثير الضبابية
|
||||
|
||||
import '../../../constant/colors.dart';
|
||||
import '../../../controller/functions/encrypt_decrypt.dart';
|
||||
import '../../../controller/functions/tts.dart';
|
||||
import '../../../controller/home/map_passenger_controller.dart';
|
||||
import '../../../controller/home/vip_waitting_page.dart';
|
||||
import '../../../env/env.dart';
|
||||
import '../../../print.dart';
|
||||
|
||||
// --- الدالة الرئيسية بالتصميم الجديد ---
|
||||
GetBuilder<MapPassengerController> leftMainMenuIcons() {
|
||||
@@ -70,11 +76,11 @@ GetBuilder<MapPassengerController> leftMainMenuIcons() {
|
||||
tooltip: 'VIP Waiting Page',
|
||||
onPressed: () => Get.to(() => VipWaittingPage()),
|
||||
),
|
||||
// _buildMapActionButton(
|
||||
// icon: Octicons.ellipsis,
|
||||
// tooltip: 'test',
|
||||
// onPressed: () => Get.to(() => TestPage()),
|
||||
// ),
|
||||
_buildMapActionButton(
|
||||
icon: Octicons.ellipsis,
|
||||
tooltip: 'test',
|
||||
onPressed: () => Get.to(() => TestPage()),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -118,15 +124,20 @@ class TestPage extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final firebaseMessagesController =
|
||||
Get.isRegistered<FirebaseMessagesController>()
|
||||
? Get.find<FirebaseMessagesController>()
|
||||
: Get.put(FirebaseMessagesController());
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: TextButton(
|
||||
onPressed: () async {},
|
||||
onPressed: () async {
|
||||
var token =
|
||||
'e4t5mB-WTsyhi2M0v5AOAy:APA91bGmQG8gcitcJB7x69oHCweCn44NdljP5ZVlO1IK62w62Gac4dCIjE3SMFPV6YcFdTMQrRHE1BXnbktEM19JE4xjcEyLz-GwC1HrCbDl2X24d4PfrPQ';
|
||||
NotificationService.sendNotification(
|
||||
target: token,
|
||||
title: 'Hi ,I will go now',
|
||||
body: 'A passenger is waiting for you.',
|
||||
isTopic: false, // Important: this is a token
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
"Text Button",
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user