12/12/2
This commit is contained in:
@@ -6,6 +6,8 @@ import 'package:location/location.dart';
|
||||
import 'package:ride/constant/box_name.dart';
|
||||
import 'package:ride/constant/links.dart';
|
||||
import 'package:ride/controller/functions/crud.dart';
|
||||
import 'package:ride/controller/home/captin/home_captain_controller.dart';
|
||||
import 'package:ride/controller/home/payment/captain_wallet_controller.dart';
|
||||
import 'package:ride/main.dart';
|
||||
|
||||
// LocationController.dart
|
||||
@@ -13,8 +15,9 @@ class LocationController extends GetxController {
|
||||
LocationData? _currentLocation;
|
||||
late Location location;
|
||||
bool isLoading = false;
|
||||
bool isActive = false;
|
||||
LatLng myLocation = const LatLng(32.3, 36.3);
|
||||
|
||||
String totalPoints = '0';
|
||||
LocationData? get currentLocation => _currentLocation;
|
||||
Timer? _locationTimer;
|
||||
|
||||
@@ -22,11 +25,17 @@ class LocationController extends GetxController {
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
location = Location();
|
||||
totalPoints = Get.find<CaptainWalletController>().totalPoints;
|
||||
}
|
||||
|
||||
void startLocationUpdates() async {
|
||||
_locationTimer = Timer.periodic(const Duration(seconds: 20), (timer) async {
|
||||
try {
|
||||
totalPoints = Get.find<CaptainWalletController>().totalPoints;
|
||||
|
||||
// if (isActive) {
|
||||
// if (double.parse(totalPoints) > -100) {
|
||||
print('total point is ll$totalPoints');
|
||||
await getLocation();
|
||||
|
||||
await CRUD().post(link: AppLink.addCarsLocationByPassenger, payload: {
|
||||
@@ -35,6 +44,9 @@ class LocationController extends GetxController {
|
||||
'longitude': myLocation.longitude.toString(),
|
||||
'status': box.read(BoxName.statusDriverLocation).toString()
|
||||
});
|
||||
// }
|
||||
|
||||
// }
|
||||
} catch (e) {
|
||||
// Handle the error gracefully
|
||||
print('Error during location updates: $e');
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import 'package:ride/constant/links.dart';
|
||||
import 'package:ride/controller/functions/crud.dart';
|
||||
import 'package:ride/main.dart';
|
||||
|
||||
import '../../../views/home/my_wallet/walet_captain.dart';
|
||||
|
||||
class CaptainWalletController extends GetxController {
|
||||
bool isLoading = false;
|
||||
Map walletDate = {};
|
||||
|
||||
@@ -145,13 +145,11 @@ class HomeCaptain extends StatelessWidget {
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
'Active Duration:'.tr +
|
||||
' ${homeCaptainController.stringActiveDuration} ',
|
||||
'${'Active Duration:'.tr} ${homeCaptainController.stringActiveDuration} ',
|
||||
style: AppStyle.title,
|
||||
),
|
||||
Text(
|
||||
'Total Connection Duration:'.tr +
|
||||
' ${homeCaptainController.totalDurationToday} ',
|
||||
'${'Total Connection Duration:'.tr} ${homeCaptainController.totalDurationToday} ',
|
||||
style: AppStyle.title,
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user