This commit is contained in:
Hamza-Ayed
2023-12-12 23:29:18 +03:00
parent 44505dd9ea
commit 99b61fd894
5 changed files with 100 additions and 46 deletions

View File

@@ -4,16 +4,17 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:ride/constant/box_name.dart';
import 'package:ride/controller/home/captin/order_request_controller.dart';
import 'dart:async';
import '../../../constant/links.dart';
import '../../../constant/style.dart';
import '../../../constant/table_names.dart';
import '../../../main.dart';
import '../../../views/home/my_wallet/walet_captain.dart';
import '../../../views/widgets/elevated_btn.dart';
import '../../functions/crud.dart';
import '../../functions/location_controller.dart';
import '../payment/captain_wallet_controller.dart';
class HomeCaptainController extends GetxController {
bool isActive = false;
@@ -26,6 +27,7 @@ class HomeCaptainController extends GetxController {
String totalMoneyInSEFER = '0';
String totalDurationToday = '0';
Timer? timer;
String totalPoints = '0';
String countRefuse = '0';
bool mapType = false;
bool mapTrafficON = false;
@@ -39,17 +41,30 @@ class HomeCaptainController extends GetxController {
return "${duration.inHours}:$twoDigitMinutes:$twoDigitSeconds";
}
void goToWalletFromConnect() {
Get.back();
Get.back();
Get.to(() => WaletCaptain());
}
String stringActiveDuration = '';
void onButtonSelected() {
totalPoints = Get.find<CaptainWalletController>().totalPoints;
// if (double.parse(totalPoints) > -100) {
// isActive = false;
// update();
// } else {
isActive = !isActive;
if (isActive) {
locationController.startLocationUpdates();
activeStartTime = DateTime.now();
activeTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
activeDuration = DateTime.now().difference(activeStartTime!);
stringActiveDuration = formatDuration(activeDuration);
update();
});
if (double.parse(totalPoints) > -100) {
locationController.startLocationUpdates();
activeStartTime = DateTime.now();
activeTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
activeDuration = DateTime.now().difference(activeStartTime!);
stringActiveDuration = formatDuration(activeDuration);
update();
});
}
} else {
locationController.stopLocationUpdates();
@@ -57,8 +72,9 @@ class HomeCaptainController extends GetxController {
activeTimer?.cancel();
savePeriod(activeDuration);
activeDuration = Duration.zero;
update();
}
update();
// }
}
void getRefusedOrderByCaptain() async {
@@ -79,13 +95,15 @@ class HomeCaptainController extends GetxController {
await sql.getCustomQuery(customQuery);
countRefuse = results[0]['count'].toString();
update();
if (int.parse(countRefuse) > 3) {
if (int.parse(countRefuse) > 3 || double.parse(totalPoints) < -100) {
print('total point is $totalPoints');
locationController.stopLocationUpdates();
activeStartTime = null;
activeTimer?.cancel();
savePeriod(activeDuration);
activeDuration = Duration.zero;
update();
Get.defaultDialog(
// backgroundColor: CupertinoColors.destructiveRed,
barrierDismissible: false,
@@ -163,6 +181,7 @@ class HomeCaptainController extends GetxController {
getAllPayment();
startPeriodicExecution();
getRefusedOrderByCaptain();
totalPoints = Get.find<CaptainWalletController>().totalPoints;
super.onInit();
}

View File

@@ -1,5 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:ride/controller/home/payment/captain_wallet_controller.dart';
import 'package:ride/views/home/my_wallet/walet_captain.dart';
import '../../../../constant/style.dart';
import '../../../../views/widgets/elevated_btn.dart';
@@ -15,40 +17,61 @@ class ConnectWidget extends StatelessWidget {
Widget build(BuildContext context) {
final OrderRequestController orderRequestController =
Get.put(OrderRequestController());
CaptainWalletController captainWalletController =
Get.put(CaptainWalletController());
captainWalletController.getCaptainWalletFromBuyPoints();
return Center(
child: GetBuilder<HomeCaptainController>(
builder: (homeCaptainController) =>
int.parse(orderRequestController.countRefuse) > 3
? CupertinoButton(
child: Text('You are Stopped'.tr),
onPressed: () {
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!'
builder: (homeCaptainController) => int.parse(
orderRequestController.countRefuse) >
3 ||
double.parse(captainWalletController.totalPoints) < -100
? CupertinoButton(
onPressed: () {
Get.defaultDialog(
// backgroundColor: CupertinoColors.destructiveRed,
barrierDismissible: false,
title: double.parse(captainWalletController.totalPoints) <
-100
? 'You dont have Points'
: 'You Are Stopped For this Day !'.tr,
titleStyle: AppStyle.title,
content: Text(
double.parse(captainWalletController.totalPoints) < -100
? 'You will be charge your Account'.tr
: '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();
Get.back();
}));
},
color: CupertinoColors.destructiveRed,
)
: CupertinoButton(
child: Text(homeCaptainController.isActive
? 'Connected'.tr
: 'Not Connected'.tr),
onPressed: homeCaptainController.onButtonSelected,
color: homeCaptainController.isActive
? CupertinoColors.activeGreen
: CupertinoColors.inactiveGray,
),
style: AppStyle.title,
),
confirm:
double.parse(captainWalletController.totalPoints) <
-100
? MyElevatedButton(
title: 'Charge your Account'.tr,
onPressed: () {
homeCaptainController
.goToWalletFromConnect();
})
: MyElevatedButton(
title: 'Ok , See you Tomorrow'.tr,
onPressed: () {
Get.back();
Get.back();
}));
},
color: CupertinoColors.destructiveRed,
child: Text('You are Stopped'.tr),
)
: CupertinoButton(
onPressed: homeCaptainController.onButtonSelected,
color: homeCaptainController.isActive
? CupertinoColors.activeGreen
: CupertinoColors.inactiveGray,
child: Text(homeCaptainController.isActive
? 'Connected'.tr
: 'Not Connected'.tr),
),
),
);
}