9/27/1
This commit is contained in:
1
lib/controller/home/captin/LocationService.dart
Normal file
1
lib/controller/home/captin/LocationService.dart
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
@@ -3,22 +3,29 @@ import 'package:ride/constant/box_name.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import '../../../main.dart';
|
||||
import '../../functions/location_controller.dart';
|
||||
|
||||
class HomeCaptainController extends GetxController {
|
||||
bool isActive = false;
|
||||
DateTime? activeStartTime;
|
||||
Duration activeDuration = Duration.zero;
|
||||
Timer? activeTimer;
|
||||
// Inject the LocationController class
|
||||
final locationController = Get.find<LocationController>();
|
||||
|
||||
void onButtonSelected() {
|
||||
isActive = !isActive;
|
||||
|
||||
if (isActive) {
|
||||
locationController.startLocationUpdates();
|
||||
activeStartTime = DateTime.now();
|
||||
activeTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
activeDuration = DateTime.now().difference(activeStartTime!);
|
||||
update();
|
||||
});
|
||||
} else {
|
||||
locationController.stopLocationUpdates();
|
||||
|
||||
activeStartTime = null;
|
||||
activeTimer?.cancel();
|
||||
savePeriod(activeDuration);
|
||||
|
||||
@@ -1,20 +1,72 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:ride/constant/colors.dart';
|
||||
import 'package:ride/constant/links.dart';
|
||||
import 'package:ride/constant/style.dart';
|
||||
import 'package:ride/main.dart';
|
||||
import 'package:ride/views/widgets/elevated_btn.dart';
|
||||
|
||||
import '../../../constant/box_name.dart';
|
||||
import '../../../constant/table_names.dart';
|
||||
import '../../functions/crud.dart';
|
||||
|
||||
class TimerController extends GetxController {
|
||||
class OrderRequestController extends GetxController {
|
||||
double progress = 0;
|
||||
int duration = 25;
|
||||
int remainingTime = 0;
|
||||
String countRefuse = '0';
|
||||
bool applied = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
// startTimer();//TODO check if it true
|
||||
getRefusedOrderByCaptain();
|
||||
update();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
void startTimer() async {
|
||||
void changeApplied() {
|
||||
applied = true;
|
||||
update();
|
||||
}
|
||||
|
||||
void getRefusedOrderByCaptain() async {
|
||||
DateTime today = DateTime.now();
|
||||
int todayDay = today.day;
|
||||
|
||||
String driverId = box.read(BoxName.driverID).toString();
|
||||
|
||||
String customQuery = '''
|
||||
SELECT COUNT(*) AS count
|
||||
FROM ${TableName.driverOrdersRefuse}
|
||||
WHERE driver_id = '$driverId'
|
||||
AND created_at LIKE '%$todayDay%'
|
||||
''';
|
||||
|
||||
try {
|
||||
List<Map<String, dynamic>> results =
|
||||
await sql.getCustomQuery(customQuery);
|
||||
countRefuse = results[0]['count'].toString();
|
||||
update();
|
||||
if (int.parse(countRefuse) > 3) {
|
||||
Get.defaultDialog(
|
||||
// backgroundColor: CupertinoColors.destructiveRed,
|
||||
barrierDismissible: false,
|
||||
title: 'You Are Stopped For this Day !'.tr,
|
||||
content: Text(
|
||||
'You Refused 3 Rides this Day that is the reason \nSee you Tomorrow!'
|
||||
.tr,
|
||||
style: AppStyle.title,
|
||||
),
|
||||
confirm: MyElevatedButton(
|
||||
title: 'Ok , See you Tomorrow'.tr,
|
||||
onPressed: () => Get.back()));
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error executing custom query: $e');
|
||||
}
|
||||
}
|
||||
|
||||
void startTimer(String driverID, orderID) async {
|
||||
for (int i = 0; i <= duration; i++) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
progress = i / duration;
|
||||
@@ -22,21 +74,29 @@ class TimerController extends GetxController {
|
||||
|
||||
update();
|
||||
}
|
||||
timerEnded();
|
||||
if (remainingTime == 0) {
|
||||
if (applied == false) {
|
||||
print('applied=========================');
|
||||
print(applied);
|
||||
refuseOrder(driverID, orderID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void refuseOrder(String driverID, orderID) async {
|
||||
await CRUD().postFromDialogue(link: AppLink.addDriverOrder, payload: {
|
||||
'driver_id': driverID,
|
||||
'driver_id': box.read(BoxName.driverID).toString(),
|
||||
// box.read(BoxName.driverID).toString(),
|
||||
'order_id': orderID,
|
||||
'status': 'Refused'
|
||||
});
|
||||
Get.back();
|
||||
}
|
||||
|
||||
void timerEnded() async {
|
||||
print('Timer ended');
|
||||
// refuseOrder();
|
||||
sql.insertData({
|
||||
'order_id': orderID,
|
||||
'created_at': DateTime.now().toString(),
|
||||
'driver_id': box.read(BoxName.driverID).toString(),
|
||||
}, TableName.driverOrdersRefuse);
|
||||
getRefusedOrderByCaptain();
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../home_captain_controller.dart';
|
||||
import '../order_request_controller.dart';
|
||||
|
||||
class ConnectWidget extends StatelessWidget {
|
||||
const ConnectWidget({
|
||||
@@ -10,17 +11,26 @@ class ConnectWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final OrderRequestController orderRequestController =
|
||||
Get.put(OrderRequestController());
|
||||
return Center(
|
||||
child: GetBuilder<HomeCaptainController>(
|
||||
builder: (homeCaptainController) => CupertinoButton(
|
||||
child: Text(homeCaptainController.isActive
|
||||
? 'Connected'.tr
|
||||
: 'Not Connected'.tr),
|
||||
onPressed: homeCaptainController.onButtonSelected,
|
||||
color: homeCaptainController.isActive
|
||||
? CupertinoColors.activeGreen
|
||||
: CupertinoColors.inactiveGray,
|
||||
),
|
||||
builder: (homeCaptainController) =>
|
||||
int.parse(orderRequestController.countRefuse) > 3
|
||||
? CupertinoButton(
|
||||
child: Text('You are Stopped'.tr),
|
||||
onPressed: () {},
|
||||
color: CupertinoColors.destructiveRed,
|
||||
)
|
||||
: CupertinoButton(
|
||||
child: Text(homeCaptainController.isActive
|
||||
? 'Connected'.tr
|
||||
: 'Not Connected'.tr),
|
||||
onPressed: homeCaptainController.onButtonSelected,
|
||||
color: homeCaptainController.isActive
|
||||
? CupertinoColors.activeGreen
|
||||
: CupertinoColors.inactiveGray,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user