343 lines
13 KiB
Dart
343 lines
13 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:SEFER/constant/colors.dart';
|
|
import 'package:SEFER/constant/style.dart';
|
|
import 'package:SEFER/controller/home/map_passenger_controller.dart';
|
|
import 'package:SEFER/views/widgets/elevated_btn.dart';
|
|
import 'package:SEFER/views/widgets/my_textField.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../../constant/links.dart';
|
|
|
|
// class SearchingCaptainWindow extends StatelessWidget {
|
|
// const SearchingCaptainWindow({super.key});
|
|
|
|
// Widget _buildDriverAvatars(MapPassengerController controller) {
|
|
// // If no drivers yet, show loading indicator
|
|
// if (controller.isSearchingWindow) {
|
|
// // Check if dataCarsLocationByPassenger or its 'data' is null
|
|
// if (controller.dataCarsLocationByPassenger == null ||
|
|
// controller.dataCarsLocationByPassenger['data'] == null ||
|
|
// controller.dataCarsLocationByPassenger['data'].isEmpty) {
|
|
// return const SizedBox(
|
|
// height: 60,
|
|
// child: Center(
|
|
// child: CircularProgressIndicator(
|
|
// valueColor:
|
|
// AlwaysStoppedAnimation<Color>(AppColor.secondaryColor),
|
|
// ),
|
|
// ),
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
// return SizedBox(
|
|
// height: 60,
|
|
// child: ListView.builder(
|
|
// scrollDirection: Axis.horizontal,
|
|
// itemCount: controller.dataCarsLocationByPassenger['data'].length,
|
|
// padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
// itemBuilder: (context, index) {
|
|
// final driver = controller.dataCarsLocationByPassenger['data'][index];
|
|
// return Padding(
|
|
// padding: const EdgeInsets.only(right: 8),
|
|
// child: Column(
|
|
// mainAxisSize: MainAxisSize.min,
|
|
// children: [
|
|
// CircleAvatar(
|
|
// radius: 25,
|
|
// backgroundColor: AppColor.secondaryColor,
|
|
// child: ClipOval(
|
|
// child: Image.network(
|
|
// '${AppLink.server}/portrate_captain_image/${driver['driver_id']}.jpg',
|
|
// width: 50,
|
|
// height: 50,
|
|
// fit: BoxFit.cover,
|
|
// errorBuilder: (context, error, stackTrace) {
|
|
// return const Icon(
|
|
// Icons.person,
|
|
// color: Colors.white,
|
|
// size: 30,
|
|
// );
|
|
// },
|
|
// ),
|
|
// ),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// );
|
|
// },
|
|
// ),
|
|
// );
|
|
// }
|
|
|
|
// @override
|
|
// Widget build(BuildContext context) {
|
|
// return GetBuilder<MapPassengerController>(
|
|
// builder: (mapPassengerController) {
|
|
// return mapPassengerController.isSearchingWindow
|
|
// ? Positioned(
|
|
// bottom: 0,
|
|
// left: 0,
|
|
// right: 0,
|
|
// child: Container(
|
|
// decoration: AppStyle.boxDecoration1,
|
|
// height: Get.height *
|
|
// .3, // Increased height to accommodate avatars
|
|
// child: Column(
|
|
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
// children: [
|
|
// SizedBox(
|
|
// width: Get.width * .7,
|
|
// child: const LinearProgressIndicator(
|
|
// minHeight: 6,
|
|
// backgroundColor: AppColor.yellowColor,
|
|
// color: AppColor.secondaryColor,
|
|
// ),
|
|
// ),
|
|
// mapPassengerController.driverOrderStatus == 'recive'
|
|
// ? Text(
|
|
// "Drivers received orders".tr,
|
|
// style: AppStyle.title,
|
|
// )
|
|
// : Text(
|
|
// "We are searching for the nearest driver to you"
|
|
// .tr,
|
|
// style: AppStyle.title,
|
|
// ),
|
|
// Text(
|
|
// 'please wait till driver accept your order'.tr,
|
|
// style: AppStyle.title,
|
|
// ),
|
|
// // New: Driver avatars section
|
|
// _buildDriverAvatars(mapPassengerController),
|
|
// _buildTimer(mapPassengerController),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
// )
|
|
// : const SizedBox();
|
|
// },
|
|
// );
|
|
// }
|
|
// }
|
|
|
|
class SearchingCaptainWindow extends StatelessWidget {
|
|
const SearchingCaptainWindow({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GetBuilder<MapPassengerController>(
|
|
builder: (mapPassengerController) {
|
|
return mapPassengerController.isSearchingWindow
|
|
? Positioned(
|
|
bottom: 0,
|
|
left: 0,
|
|
right: 0,
|
|
child: Container(
|
|
decoration: AppStyle.boxDecoration1,
|
|
height: Get.height * .25,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
// Use Stack for overlapping widgets
|
|
children: [
|
|
// Text elements
|
|
|
|
SizedBox(
|
|
width: Get.width * .7,
|
|
child: const LinearProgressIndicator(
|
|
minHeight: 6,
|
|
backgroundColor: AppColor.yellowColor,
|
|
color: AppColor.secondaryColor,
|
|
),
|
|
),
|
|
Text(
|
|
mapPassengerController.driversStatusForSearchWindow,
|
|
style: AppStyle.title,
|
|
),
|
|
// Text(
|
|
// "We are searching for the nearest driver to you".tr,
|
|
// style: AppStyle.title,
|
|
// ),
|
|
Text(
|
|
'please wait till driver accept your order'.tr,
|
|
style: AppStyle.title,
|
|
), // Timer logic
|
|
_buildTimer(mapPassengerController),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: const SizedBox();
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
Widget _buildTimer(MapPassengerController mapPassengerController) {
|
|
// Start timer at 0
|
|
Timer? timer;
|
|
|
|
return StreamBuilder<int>(
|
|
// Use StreamBuilder for timer updates
|
|
stream: Stream.periodic(const Duration(seconds: 1))
|
|
.map((_) => ++mapPassengerController.currentTimeSearchingCaptainWindow),
|
|
initialData: 0,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasData && snapshot.data! > 30) {
|
|
timer?.cancel(); // Cancel timer after 60 seconds
|
|
return GestureDetector(
|
|
onTap: () {
|
|
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.title,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
IconButton(
|
|
onPressed: () {
|
|
mapPassengerController.increasFeeFromPassenger.text =
|
|
(mapPassengerController.totalPassenger + 3)
|
|
.toStringAsFixed(1);
|
|
// mapPassengerController.increasFeeFromPassenger.text =
|
|
// mapPassengerController.totalPassenger
|
|
// .toStringAsFixed(1);
|
|
mapPassengerController.update();
|
|
},
|
|
icon: Column(
|
|
children: [
|
|
Text(
|
|
'3',
|
|
style: AppStyle.number,
|
|
),
|
|
Container(
|
|
decoration: const BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: AppColor.greenColor),
|
|
child: const Icon(
|
|
Icons.arrow_circle_up,
|
|
size: 30,
|
|
color: AppColor.secondaryColor,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
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: () {
|
|
// if ((double.parse(mapPassengerController
|
|
// .increasFeeFromPassenger.text) >
|
|
// totalPassenger)) {}
|
|
mapPassengerController.increasFeeFromPassenger.text =
|
|
(mapPassengerController.totalPassenger - 3)
|
|
.toStringAsFixed(1);
|
|
// mapPassengerController.increasFeeFromPassenger.text =
|
|
// mapPassengerController.totalPassenger
|
|
// .toStringAsFixed(1);
|
|
mapPassengerController.update();
|
|
},
|
|
icon: Column(
|
|
children: [
|
|
Text(
|
|
'3',
|
|
style: AppStyle.number,
|
|
),
|
|
Container(
|
|
decoration: const BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: AppColor.redColor),
|
|
child: const Icon(
|
|
Icons.arrow_drop_down_circle_outlined,
|
|
size: 30,
|
|
color: AppColor.secondaryColor,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
)
|
|
],
|
|
),
|
|
actions: [
|
|
MyElevatedButton(
|
|
title: "No, thanks",
|
|
onPressed: () {
|
|
Get.back();
|
|
mapPassengerController.cancelRide();
|
|
}),
|
|
MyElevatedButton(
|
|
title: "Increase Fee".tr,
|
|
kolor: AppColor.greenColor,
|
|
onPressed: () {
|
|
mapPassengerController.increaseFeeByPassengerAndReOrder();
|
|
})
|
|
],
|
|
);
|
|
},
|
|
child: Text(
|
|
"No accepted orders? Try raising your trip fee to attract riders."
|
|
.tr,
|
|
style: AppStyle.title.copyWith(color: AppColor.blueColor),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Update progress for circular indicator (0.0 to 1.0)
|
|
final double progress =
|
|
snapshot.data!.toDouble() / 30.0; // Normalize progress
|
|
|
|
return Stack(
|
|
children: [
|
|
SizedBox(
|
|
height: 35,
|
|
width: 35,
|
|
child: Center(
|
|
child: CircularProgressIndicator(
|
|
value: progress, // Use calculated progress
|
|
color: AppColor.blueColor,
|
|
backgroundColor: AppColor.yellowColor,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 35,
|
|
width: 35,
|
|
child: Center(
|
|
child: Text(
|
|
'${snapshot.data} ', // Display elapsed time
|
|
style: AppStyle.title.copyWith(
|
|
color: AppColor.greenColor), // Adjust color for timer
|
|
),
|
|
),
|
|
)
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|