263 lines
9.2 KiB
Dart
263 lines
9.2 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:SEFER/constant/colors.dart';
|
|
import 'package:SEFER/constant/style.dart';
|
|
import 'package:SEFER/controller/notification/ride_available_controller.dart';
|
|
import 'package:SEFER/views/widgets/my_scafold.dart';
|
|
import 'package:SEFER/views/widgets/mycircular.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
import '../../constant/box_name.dart';
|
|
import '../../constant/links.dart';
|
|
import '../../controller/firebase/firbase_messge.dart';
|
|
import '../../controller/functions/crud.dart';
|
|
import '../../controller/home/captin/home_captain_controller.dart';
|
|
import '../../main.dart';
|
|
import '../home/Captin/driver_map_page.dart';
|
|
import '../widgets/mydialoug.dart';
|
|
|
|
class AvailableRidesPage extends StatelessWidget {
|
|
const AvailableRidesPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Get.put(RideAvailableController());
|
|
return GetBuilder<RideAvailableController>(
|
|
builder: (rideAvailableController) {
|
|
return MyScafolld(
|
|
title: 'Available for rides'.tr,
|
|
body: [
|
|
rideAvailableController.isLoading
|
|
? const MyCircularProgressIndicator()
|
|
: ListView.builder(
|
|
itemCount: rideAvailableController
|
|
.rideAvailableMap['message'].length,
|
|
itemBuilder: (context, index) => RideAvailableCard(
|
|
rideInfo: rideAvailableController
|
|
.rideAvailableMap['message'][index],
|
|
),
|
|
)
|
|
],
|
|
isleading: true);
|
|
});
|
|
}
|
|
}
|
|
|
|
class RideAvailableCard extends StatelessWidget {
|
|
final Map<String, dynamic> rideInfo;
|
|
|
|
const RideAvailableCard({Key? key, required this.rideInfo}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Card(
|
|
margin: const EdgeInsets.all(8.0),
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
|
elevation: 4,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
_buildLocationRow('↑', rideInfo['startName'], AppColor.greenColor),
|
|
const SizedBox(height: 8),
|
|
_buildLocationRow('↓', rideInfo['endName'], Colors.red),
|
|
const SizedBox(height: 16),
|
|
_buildInfoRow(),
|
|
const SizedBox(height: 16),
|
|
_buildActionRow(),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildLocationRow(String icon, String location, Color iconColor) {
|
|
return Row(
|
|
children: [
|
|
Text(
|
|
icon,
|
|
style: TextStyle(
|
|
fontSize: 20, fontWeight: FontWeight.bold, color: iconColor),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Text(
|
|
location,
|
|
style: AppStyle.subtitle,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildInfoRow() {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text('${'Price:'.tr} ${rideInfo['price']} \$', style: AppStyle.title),
|
|
Text(
|
|
rideInfo['carType'],
|
|
style: AppStyle.title.copyWith(color: AppColor.greenColor),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildActionRow() {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text('📈 ${rideInfo['passengerRate']}', style: AppStyle.title),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'📍 ${rideInfo['distance']} ${'KM'.tr}',
|
|
style: AppStyle.title.copyWith(color: AppColor.greenColor),
|
|
),
|
|
],
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () => _acceptRide(),
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppColor.greenColor,
|
|
shape:
|
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
|
),
|
|
child: Text('Accept'.tr),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
void _acceptRide() async {
|
|
var res = await CRUD().post(link: AppLink.updateStausFromSpeed, payload: {
|
|
'id': rideInfo['id'],
|
|
'rideTimeStart': DateTime.now().toString(),
|
|
'status': 'Apply',
|
|
'driver_id': box.read(BoxName.driverID),
|
|
});
|
|
if (AppLink.endPoint.toString() != AppLink.seferCairoServer) {
|
|
CRUD().post(
|
|
link: '${AppLink.endPoint}rides/updateStausFromSpeed.php',
|
|
payload: {
|
|
'id': rideInfo['id'],
|
|
'rideTimeStart': DateTime.now().toString(),
|
|
'status': 'Apply',
|
|
'driver_id': box.read(BoxName.driverID),
|
|
});
|
|
}
|
|
|
|
// .then((value) {
|
|
// var json = jsonDecode(res);
|
|
if (res == "failure") {
|
|
MyDialog().getDialog(
|
|
"This ride is already taken by another driver.".tr, '', () {
|
|
CRUD().post(
|
|
link: AppLink.deleteAvailableRide, payload: {'id': rideInfo['id']});
|
|
if (AppLink.endPoint.toString() != AppLink.seferCairoServer) {
|
|
CRUD().post(
|
|
link:
|
|
'${AppLink.endPoint}/ride/notificationCaptain/deleteAvailableRide.php',
|
|
payload: {'id': rideInfo['id']});
|
|
}
|
|
Get.back();
|
|
});
|
|
} else if (jsonDecode(res)['status'] == "success") {
|
|
List<String> bodyToPassenger = [
|
|
box.read(BoxName.driverID).toString(),
|
|
box.read(BoxName.nameDriver).toString(),
|
|
box.read(BoxName.tokenDriver).toString(),
|
|
];
|
|
box.write(BoxName.statusDriverLocation, 'on');
|
|
await CRUD().postFromDialogue(link: AppLink.addDriverOrder, payload: {
|
|
'driver_id': box.read(BoxName.driverID),
|
|
// box.read(BoxName.driverID).toString(),
|
|
'order_id': rideInfo['id'],
|
|
'status': 'Apply'
|
|
});
|
|
if (AppLink.endPoint.toString() != AppLink.seferCairoServer) {
|
|
CRUD().postFromDialogue(
|
|
link: '${AppLink.endPoint}/driver_order/add.php',
|
|
payload: {
|
|
'driver_id': box.read(BoxName.driverID),
|
|
// box.read(BoxName.driverID).toString(),
|
|
'order_id': rideInfo['id'],
|
|
'status': 'Apply'
|
|
});
|
|
}
|
|
await CRUD().post(link: AppLink.updateRides, payload: {
|
|
'id': rideInfo['id'],
|
|
'DriverIsGoingToPassenger': DateTime.now().toString(),
|
|
'status': 'Applied'
|
|
});
|
|
if (AppLink.endPoint.toString() != AppLink.seferCairoServer) {
|
|
CRUD().post(link: '${AppLink.endPoint}/rides/update.php', payload: {
|
|
'id': rideInfo['id'],
|
|
'DriverIsGoingToPassenger': DateTime.now().toString(),
|
|
'status': 'Applied'
|
|
});
|
|
}
|
|
|
|
await CRUD().post(
|
|
link: AppLink.updateWaitingRide,
|
|
payload: {'id': rideInfo['id'], 'status': 'Applied'});
|
|
if (AppLink.endPoint.toString() != AppLink.seferCairoServer) {
|
|
CRUD().post(
|
|
link:
|
|
"${AppLink.endPoint}/ride/notificationCaptain/updateWaitingTrip.php",
|
|
payload: {'id': rideInfo['id'], 'status': 'Applied'});
|
|
}
|
|
FirebaseMessagesController().sendNotificationToPassengerToken(
|
|
'Apply Ride',
|
|
'your ride is applied'.tr,
|
|
// arguments['DriverList'][9].toString(),
|
|
rideInfo['passengerToken'].toString(),
|
|
// box.read(BoxName.tokenDriver).toString(),
|
|
bodyToPassenger,
|
|
'start.wav');
|
|
Get.back();
|
|
Get.to(() => PassengerLocationMapPage(), arguments: {
|
|
'passengerLocation': rideInfo['start_location'].toString(),
|
|
'passengerDestination': rideInfo['end_location'].toString(),
|
|
'Duration': rideInfo['duration'].toString(),
|
|
'totalCost': rideInfo['price'].toString(),
|
|
'Distance': rideInfo['distance'].toString(),
|
|
'name': rideInfo['first_name'].toString(),
|
|
'phone': rideInfo['phone'].toString(),
|
|
'email': rideInfo['email'].toString(),
|
|
'WalletChecked': rideInfo['payment_method'].toString(),
|
|
'tokenPassenger': rideInfo['passengerToken'].toString(),
|
|
'direction':
|
|
'https://www.google.com/maps/dir/${rideInfo['start_location']}/${rideInfo['end_location']}/',
|
|
'DurationToPassenger': rideInfo['duration'].toString(),
|
|
'rideId': rideInfo['id'].toString(),
|
|
'passengerId': rideInfo['passenger_id'].toString(),
|
|
'driverId': box.read(BoxName.driverID).toString(),
|
|
'durationOfRideValue': rideInfo['duration'].toString(),
|
|
'paymentAmount': rideInfo['price'].toString(),
|
|
'paymentMethod': 'cash'.toString() == //todo fix payment method
|
|
'true'
|
|
? 'visa'
|
|
: 'cash',
|
|
'isHaveSteps': 'startEnd'.toString(),
|
|
'step0': ''.toString(),
|
|
'step1': ''.toString(),
|
|
'step2': ''.toString(),
|
|
'step3': ''.toString(),
|
|
'step4': ''.toString(),
|
|
'passengerWalletBurc': rideInfo['bruc'].toString(),
|
|
'timeOfOrder': DateTime.now().toString(),
|
|
'totalPassenger': rideInfo['price'].toString(),
|
|
'carType': rideInfo['carType'].toString(),
|
|
'kazan': Get.find<HomeCaptainController>().kazan.toString(),
|
|
});
|
|
}
|
|
}
|
|
}
|