469 lines
17 KiB
Dart
469 lines
17 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:Intaleq/constant/colors.dart';
|
|
import 'package:Intaleq/constant/style.dart';
|
|
import 'package:Intaleq/controller/home/map_passenger_controller.dart';
|
|
|
|
// --- الويدجت الرئيسية بالتصميم الجديد ---
|
|
class SearchingCaptainWindow extends StatefulWidget {
|
|
const SearchingCaptainWindow({super.key});
|
|
|
|
@override
|
|
State<SearchingCaptainWindow> createState() => _SearchingCaptainWindowState();
|
|
}
|
|
|
|
class _SearchingCaptainWindowState extends State<SearchingCaptainWindow>
|
|
with SingleTickerProviderStateMixin {
|
|
late AnimationController _animationController;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_animationController = AnimationController(
|
|
vsync: this,
|
|
duration: const Duration(seconds: 2),
|
|
)..repeat();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_animationController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
// [تعديل 1] نستخدم Obx للاستماع إلى التغييرات في حالة الرحلة
|
|
return Obx(() {
|
|
// ابحث عن الكنترولر مرة واحدة
|
|
final controller = Get.find<MapPassengerController>();
|
|
|
|
// [تعديل 2] شرط الإظهار يعتمد الآن على حالة الرحلة مباشرة
|
|
final bool isVisible =
|
|
controller.currentRideState.value == RideState.searching;
|
|
|
|
return AnimatedPositioned(
|
|
duration: const Duration(milliseconds: 300),
|
|
curve: Curves.easeInOut,
|
|
bottom: isVisible ? 0 : -Get.height * 0.45, // زيادة الارتفاع قليلاً
|
|
left: 0,
|
|
right: 0,
|
|
child: Container(
|
|
padding: const EdgeInsets.fromLTRB(20, 20, 20, 16),
|
|
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,
|
|
offset: const Offset(0, -5),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
// --- 1. أنيميشن الرادار ---
|
|
_buildRadarAnimation(controller),
|
|
const SizedBox(height: 20),
|
|
|
|
// --- 2. زر الإلغاء ---
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: OutlinedButton(
|
|
onPressed: () {
|
|
// [تعديل 3] استدعاء دالة الإلغاء الموحدة
|
|
controller.cancelRide();
|
|
},
|
|
style: OutlinedButton.styleFrom(
|
|
foregroundColor: AppColor.writeColor,
|
|
side:
|
|
BorderSide(color: AppColor.writeColor.withOpacity(0.3)),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(12)),
|
|
padding: const EdgeInsets.symmetric(vertical: 12),
|
|
),
|
|
child: Text('Cancel Search'.tr),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
// --- ويدجت بناء أنيميشن الرادار ---
|
|
Widget _buildRadarAnimation(MapPassengerController controller) {
|
|
return SizedBox(
|
|
height: 180, // ارتفاع ثابت لمنطقة الأنيميشن
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
// --- دوائر الرادار المتحركة (تبقى كما هي) ---
|
|
...List.generate(3, (index) {
|
|
return FadeTransition(
|
|
opacity: Tween<double>(begin: 1.0, end: 0.0).animate(
|
|
CurvedAnimation(
|
|
parent: _animationController,
|
|
curve: Interval((index) / 3, 1.0, curve: Curves.easeInOut),
|
|
),
|
|
),
|
|
child: ScaleTransition(
|
|
scale: Tween<double>(begin: 0.3, end: 1.0).animate(
|
|
CurvedAnimation(
|
|
parent: _animationController,
|
|
curve: Interval((index) / 3, 1.0, curve: Curves.easeInOut),
|
|
),
|
|
),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
border: Border.all(
|
|
color: AppColor.primaryColor.withOpacity(0.7),
|
|
width: 2,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}),
|
|
// --- المحتوى في المنتصف ---
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
// [تعديل 4] النص يأتي مباشرة من الكنترولر
|
|
controller.driversStatusForSearchWindow,
|
|
style: AppStyle.headTitle.copyWith(fontSize: 20),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'Searching for the nearest captain...'.tr,
|
|
style: AppStyle.subtitle
|
|
.copyWith(color: AppColor.writeColor.withOpacity(0.7)),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// --- [!! تعديل جوهري !!] ---
|
|
// لم نعد بحاجة لـ buildTimerForIncrease
|
|
// المؤقت الرئيسي في الكنترولر هو من يقرر متى يعرض الحوار
|
|
// وهذا الجزء من الواجهة أصبح "غبياً" (لا يحتوي على منطق)
|
|
// الكنترولر سيستدعي _showIncreaseFeeDialog مباشرة
|
|
SizedBox(
|
|
height: 40,
|
|
width: 40,
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
CircularProgressIndicator(
|
|
strokeWidth: 3,
|
|
color: AppColor.primaryColor,
|
|
backgroundColor: AppColor.primaryColor.withOpacity(0.2),
|
|
),
|
|
Center(
|
|
child: Icon(
|
|
Icons.search,
|
|
color: AppColor.writeColor.withOpacity(0.8),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// --- [!! تعديل جوهري !!] ---
|
|
// تم حذف دالة `buildTimerForIncrease` بالكامل.
|
|
// تم حذف دالة `_showIncreaseFeeDialog` من هذا الملف.
|
|
// لماذا؟ لأن الكنترولر الآن هو المسؤول الوحيد عن إظهار الحوار.
|
|
// دالة `_showIncreaseFeeDialog` موجودة بالفعل داخل `map_passenger_controller.dart`
|
|
// وسيتم استدعاؤها من `_handleRideState` عند انتهاء مهلة الـ 90 ثانية.
|
|
|
|
// // --- الويدجت الرئيسية بالتصميم الجديد ---
|
|
// class SearchingCaptainWindow extends StatefulWidget {
|
|
// const SearchingCaptainWindow({super.key});
|
|
|
|
// @override
|
|
// State<SearchingCaptainWindow> createState() => _SearchingCaptainWindowState();
|
|
// }
|
|
|
|
// class _SearchingCaptainWindowState extends State<SearchingCaptainWindow>
|
|
// with SingleTickerProviderStateMixin {
|
|
// late AnimationController _animationController;
|
|
|
|
// @override
|
|
// void initState() {
|
|
// super.initState();
|
|
// _animationController = AnimationController(
|
|
// vsync: this,
|
|
// duration: const Duration(seconds: 2),
|
|
// )..repeat();
|
|
// }
|
|
|
|
// @override
|
|
// void dispose() {
|
|
// _animationController.dispose();
|
|
// super.dispose();
|
|
// }
|
|
|
|
// @override
|
|
// Widget build(BuildContext context) {
|
|
// return GetBuilder<MapPassengerController>(
|
|
// builder: (controller) {
|
|
// return AnimatedPositioned(
|
|
// duration: const Duration(milliseconds: 300),
|
|
// curve: Curves.easeInOut,
|
|
// bottom: controller.isSearchingWindow ? 0 : -Get.height * 0.4,
|
|
// left: 0,
|
|
// right: 0,
|
|
// child: Container(
|
|
// padding: const EdgeInsets.fromLTRB(20, 20, 20, 16),
|
|
// 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,
|
|
// offset: const Offset(0, -5),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// child: Column(
|
|
// mainAxisSize: MainAxisSize.min,
|
|
// children: [
|
|
// // --- 1. أنيميشن الرادار ---
|
|
// _buildRadarAnimation(controller),
|
|
// const SizedBox(height: 20),
|
|
|
|
// // --- 2. زر الإلغاء ---
|
|
// SizedBox(
|
|
// width: double.infinity,
|
|
// child: OutlinedButton(
|
|
// onPressed: () {
|
|
// // --- نفس منطقك للإلغاء ---
|
|
// controller.changeCancelRidePageShow();
|
|
// },
|
|
// style: OutlinedButton.styleFrom(
|
|
// foregroundColor: AppColor.writeColor,
|
|
// side: BorderSide(
|
|
// color: AppColor.writeColor.withOpacity(0.3)),
|
|
// shape: RoundedRectangleBorder(
|
|
// borderRadius: BorderRadius.circular(12)),
|
|
// padding: const EdgeInsets.symmetric(vertical: 12),
|
|
// ),
|
|
// child: Text('Cancel Search'.tr),
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
// );
|
|
// },
|
|
// );
|
|
// }
|
|
|
|
// // --- ويدجت بناء أنيميشن الرادار ---
|
|
// Widget _buildRadarAnimation(MapPassengerController controller) {
|
|
// return SizedBox(
|
|
// height: 180, // ارتفاع ثابت لمنطقة الأنيميشن
|
|
// child: Stack(
|
|
// alignment: Alignment.center,
|
|
// children: [
|
|
// // --- دوائر الرادار المتحركة ---
|
|
// ...List.generate(3, (index) {
|
|
// return FadeTransition(
|
|
// opacity: Tween<double>(begin: 1.0, end: 0.0).animate(
|
|
// CurvedAnimation(
|
|
// parent: _animationController,
|
|
// curve: Interval((index) / 3, 1.0, curve: Curves.easeInOut),
|
|
// ),
|
|
// ),
|
|
// child: ScaleTransition(
|
|
// scale: Tween<double>(begin: 0.3, end: 1.0).animate(
|
|
// CurvedAnimation(
|
|
// parent: _animationController,
|
|
// curve: Interval((index) / 3, 1.0, curve: Curves.easeInOut),
|
|
// ),
|
|
// ),
|
|
// child: Container(
|
|
// decoration: BoxDecoration(
|
|
// shape: BoxShape.circle,
|
|
// border: Border.all(
|
|
// color: AppColor.primaryColor.withOpacity(0.7),
|
|
// width: 2,
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// );
|
|
// }),
|
|
// // --- المحتوى في المنتصف ---
|
|
// Column(
|
|
// mainAxisAlignment: MainAxisAlignment.center,
|
|
// children: [
|
|
// Text(
|
|
// controller.driversStatusForSearchWindow,
|
|
// style: AppStyle.headTitle.copyWith(fontSize: 20),
|
|
// textAlign: TextAlign.center,
|
|
// ),
|
|
// const SizedBox(height: 8),
|
|
// Text(
|
|
// 'Searching for the nearest captain...'.tr,
|
|
// style: AppStyle.subtitle
|
|
// .copyWith(color: AppColor.writeColor.withOpacity(0.7)),
|
|
// textAlign: TextAlign.center,
|
|
// ),
|
|
// const SizedBox(height: 16),
|
|
// // --- استدعاء نفس دالة المؤقت الخاصة بك ---
|
|
// buildTimerForIncrease(controller),
|
|
// ],
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// // --- نفس دالة المؤقت الخاصة بك مع تعديلات شكلية بسيطة ---
|
|
// Widget buildTimerForIncrease(MapPassengerController mapPassengerController) {
|
|
// return StreamBuilder<int>(
|
|
// stream: Stream.periodic(const Duration(seconds: 1))
|
|
// .map((_) => ++mapPassengerController.currentTimeSearchingCaptainWindow),
|
|
// initialData: 0,
|
|
// builder: (context, snapshot) {
|
|
// if (snapshot.hasData && snapshot.data! > 45) {
|
|
// // --- عرض زر زيادة الأجرة بنفس منطقك القديم ---
|
|
// return TextButton(
|
|
// onPressed: () =>
|
|
// _showIncreaseFeeDialog(context, mapPassengerController),
|
|
// child: Text(
|
|
// "No one accepted? Try increasing the fare.".tr,
|
|
// style: AppStyle.title.copyWith(
|
|
// color: AppColor.primaryColor,
|
|
// decoration: TextDecoration.underline),
|
|
// textAlign: TextAlign.center,
|
|
// ),
|
|
// );
|
|
// }
|
|
|
|
// final double progress = (snapshot.data ?? 0).toDouble() / 30.0;
|
|
|
|
// return SizedBox(
|
|
// height: 40,
|
|
// width: 40,
|
|
// child: Stack(
|
|
// fit: StackFit.expand,
|
|
// children: [
|
|
// CircularProgressIndicator(
|
|
// value: progress,
|
|
// strokeWidth: 3,
|
|
// color: AppColor.primaryColor,
|
|
// backgroundColor: AppColor.primaryColor.withOpacity(0.2),
|
|
// ),
|
|
// Center(
|
|
// child: Text(
|
|
// '${snapshot.data ?? 0}',
|
|
// style: AppStyle.title.copyWith(
|
|
// color: AppColor.writeColor, fontWeight: FontWeight.bold),
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// );
|
|
// },
|
|
// );
|
|
// }
|
|
|
|
// // --- دالة لعرض نافذة زيادة الأجرة (مأخوذة من منطقك القديم) ---
|
|
// void _showIncreaseFeeDialog(
|
|
// BuildContext context, MapPassengerController mapPassengerController) {
|
|
// Get.defaultDialog(
|
|
// barrierDismissible: false,
|
|
// title: "Increase Your Trip Fee (Optional)".tr,
|
|
// titleStyle: AppStyle.title,
|
|
// content: Column(
|
|
// children: [
|
|
// Text(
|
|
// "We haven't found any drivers yet. Consider increasing your trip fee to make your offer more attractive to drivers."
|
|
// .tr,
|
|
// style: AppStyle.subtitle,
|
|
// textAlign: TextAlign.center,
|
|
// ),
|
|
// const SizedBox(height: 16),
|
|
// Row(
|
|
// mainAxisAlignment: MainAxisAlignment.center,
|
|
// children: [
|
|
// IconButton(
|
|
// onPressed: () {
|
|
// mapPassengerController.increasFeeFromPassenger.text =
|
|
// (mapPassengerController.totalPassenger + 3)
|
|
// .toStringAsFixed(1);
|
|
// mapPassengerController.update();
|
|
// },
|
|
// icon: const Icon(Icons.add_circle,
|
|
// size: 40, color: AppColor.greenColor),
|
|
// ),
|
|
// SizedBox(
|
|
// width: 100,
|
|
// child: Form(
|
|
// key: mapPassengerController.increaseFeeFormKey,
|
|
// child: MyTextForm(
|
|
// controller: mapPassengerController.increasFeeFromPassenger,
|
|
// label:
|
|
// mapPassengerController.totalPassenger.toStringAsFixed(2),
|
|
// hint:
|
|
// mapPassengerController.totalPassenger.toStringAsFixed(2),
|
|
// type: TextInputType.number,
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// IconButton(
|
|
// onPressed: () {
|
|
// mapPassengerController.increasFeeFromPassenger.text =
|
|
// (mapPassengerController.totalPassenger - 3)
|
|
// .toStringAsFixed(1);
|
|
// mapPassengerController.update();
|
|
// },
|
|
// icon: const Icon(Icons.remove_circle,
|
|
// size: 40, color: AppColor.redColor),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// actions: [
|
|
// TextButton(
|
|
// child: Text("No, thanks".tr,
|
|
// style: const TextStyle(color: AppColor.redColor)),
|
|
// onPressed: () {
|
|
// Get.back();
|
|
// // mapPassengerController.cancelRide();
|
|
// mapPassengerController.changeCancelRidePageShow();
|
|
// },
|
|
// ),
|
|
// ElevatedButton(
|
|
// style: ElevatedButton.styleFrom(backgroundColor: AppColor.greenColor),
|
|
// child: Text("Increase Fee".tr),
|
|
// onPressed: () =>
|
|
// mapPassengerController.increaseFeeByPassengerAndReOrder(),
|
|
// ),
|
|
// ],
|
|
// );
|
|
// }
|