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/box_name.dart';
|
||||||
import 'package:ride/constant/links.dart';
|
import 'package:ride/constant/links.dart';
|
||||||
import 'package:ride/controller/functions/crud.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';
|
import 'package:ride/main.dart';
|
||||||
|
|
||||||
// LocationController.dart
|
// LocationController.dart
|
||||||
@@ -13,8 +15,9 @@ class LocationController extends GetxController {
|
|||||||
LocationData? _currentLocation;
|
LocationData? _currentLocation;
|
||||||
late Location location;
|
late Location location;
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
|
bool isActive = false;
|
||||||
LatLng myLocation = const LatLng(32.3, 36.3);
|
LatLng myLocation = const LatLng(32.3, 36.3);
|
||||||
|
String totalPoints = '0';
|
||||||
LocationData? get currentLocation => _currentLocation;
|
LocationData? get currentLocation => _currentLocation;
|
||||||
Timer? _locationTimer;
|
Timer? _locationTimer;
|
||||||
|
|
||||||
@@ -22,11 +25,17 @@ class LocationController extends GetxController {
|
|||||||
void onInit() async {
|
void onInit() async {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
location = Location();
|
location = Location();
|
||||||
|
totalPoints = Get.find<CaptainWalletController>().totalPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
void startLocationUpdates() async {
|
void startLocationUpdates() async {
|
||||||
_locationTimer = Timer.periodic(const Duration(seconds: 20), (timer) async {
|
_locationTimer = Timer.periodic(const Duration(seconds: 20), (timer) async {
|
||||||
try {
|
try {
|
||||||
|
totalPoints = Get.find<CaptainWalletController>().totalPoints;
|
||||||
|
|
||||||
|
// if (isActive) {
|
||||||
|
// if (double.parse(totalPoints) > -100) {
|
||||||
|
print('total point is ll$totalPoints');
|
||||||
await getLocation();
|
await getLocation();
|
||||||
|
|
||||||
await CRUD().post(link: AppLink.addCarsLocationByPassenger, payload: {
|
await CRUD().post(link: AppLink.addCarsLocationByPassenger, payload: {
|
||||||
@@ -35,6 +44,9 @@ class LocationController extends GetxController {
|
|||||||
'longitude': myLocation.longitude.toString(),
|
'longitude': myLocation.longitude.toString(),
|
||||||
'status': box.read(BoxName.statusDriverLocation).toString()
|
'status': box.read(BoxName.statusDriverLocation).toString()
|
||||||
});
|
});
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Handle the error gracefully
|
// Handle the error gracefully
|
||||||
print('Error during location updates: $e');
|
print('Error during location updates: $e');
|
||||||
|
|||||||
@@ -4,16 +4,17 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||||
import 'package:ride/constant/box_name.dart';
|
import 'package:ride/constant/box_name.dart';
|
||||||
import 'package:ride/controller/home/captin/order_request_controller.dart';
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import '../../../constant/links.dart';
|
import '../../../constant/links.dart';
|
||||||
import '../../../constant/style.dart';
|
import '../../../constant/style.dart';
|
||||||
import '../../../constant/table_names.dart';
|
import '../../../constant/table_names.dart';
|
||||||
import '../../../main.dart';
|
import '../../../main.dart';
|
||||||
|
import '../../../views/home/my_wallet/walet_captain.dart';
|
||||||
import '../../../views/widgets/elevated_btn.dart';
|
import '../../../views/widgets/elevated_btn.dart';
|
||||||
import '../../functions/crud.dart';
|
import '../../functions/crud.dart';
|
||||||
import '../../functions/location_controller.dart';
|
import '../../functions/location_controller.dart';
|
||||||
|
import '../payment/captain_wallet_controller.dart';
|
||||||
|
|
||||||
class HomeCaptainController extends GetxController {
|
class HomeCaptainController extends GetxController {
|
||||||
bool isActive = false;
|
bool isActive = false;
|
||||||
@@ -26,6 +27,7 @@ class HomeCaptainController extends GetxController {
|
|||||||
String totalMoneyInSEFER = '0';
|
String totalMoneyInSEFER = '0';
|
||||||
String totalDurationToday = '0';
|
String totalDurationToday = '0';
|
||||||
Timer? timer;
|
Timer? timer;
|
||||||
|
String totalPoints = '0';
|
||||||
String countRefuse = '0';
|
String countRefuse = '0';
|
||||||
bool mapType = false;
|
bool mapType = false;
|
||||||
bool mapTrafficON = false;
|
bool mapTrafficON = false;
|
||||||
@@ -39,17 +41,30 @@ class HomeCaptainController extends GetxController {
|
|||||||
return "${duration.inHours}:$twoDigitMinutes:$twoDigitSeconds";
|
return "${duration.inHours}:$twoDigitMinutes:$twoDigitSeconds";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void goToWalletFromConnect() {
|
||||||
|
Get.back();
|
||||||
|
Get.back();
|
||||||
|
Get.to(() => WaletCaptain());
|
||||||
|
}
|
||||||
|
|
||||||
String stringActiveDuration = '';
|
String stringActiveDuration = '';
|
||||||
void onButtonSelected() {
|
void onButtonSelected() {
|
||||||
|
totalPoints = Get.find<CaptainWalletController>().totalPoints;
|
||||||
|
// if (double.parse(totalPoints) > -100) {
|
||||||
|
// isActive = false;
|
||||||
|
// update();
|
||||||
|
// } else {
|
||||||
isActive = !isActive;
|
isActive = !isActive;
|
||||||
if (isActive) {
|
if (isActive) {
|
||||||
locationController.startLocationUpdates();
|
if (double.parse(totalPoints) > -100) {
|
||||||
activeStartTime = DateTime.now();
|
locationController.startLocationUpdates();
|
||||||
activeTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
activeStartTime = DateTime.now();
|
||||||
activeDuration = DateTime.now().difference(activeStartTime!);
|
activeTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||||
stringActiveDuration = formatDuration(activeDuration);
|
activeDuration = DateTime.now().difference(activeStartTime!);
|
||||||
update();
|
stringActiveDuration = formatDuration(activeDuration);
|
||||||
});
|
update();
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
locationController.stopLocationUpdates();
|
locationController.stopLocationUpdates();
|
||||||
|
|
||||||
@@ -57,8 +72,9 @@ class HomeCaptainController extends GetxController {
|
|||||||
activeTimer?.cancel();
|
activeTimer?.cancel();
|
||||||
savePeriod(activeDuration);
|
savePeriod(activeDuration);
|
||||||
activeDuration = Duration.zero;
|
activeDuration = Duration.zero;
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
update();
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void getRefusedOrderByCaptain() async {
|
void getRefusedOrderByCaptain() async {
|
||||||
@@ -79,13 +95,15 @@ class HomeCaptainController extends GetxController {
|
|||||||
await sql.getCustomQuery(customQuery);
|
await sql.getCustomQuery(customQuery);
|
||||||
countRefuse = results[0]['count'].toString();
|
countRefuse = results[0]['count'].toString();
|
||||||
update();
|
update();
|
||||||
if (int.parse(countRefuse) > 3) {
|
if (int.parse(countRefuse) > 3 || double.parse(totalPoints) < -100) {
|
||||||
|
print('total point is $totalPoints');
|
||||||
locationController.stopLocationUpdates();
|
locationController.stopLocationUpdates();
|
||||||
activeStartTime = null;
|
activeStartTime = null;
|
||||||
activeTimer?.cancel();
|
activeTimer?.cancel();
|
||||||
savePeriod(activeDuration);
|
savePeriod(activeDuration);
|
||||||
activeDuration = Duration.zero;
|
activeDuration = Duration.zero;
|
||||||
update();
|
update();
|
||||||
|
|
||||||
Get.defaultDialog(
|
Get.defaultDialog(
|
||||||
// backgroundColor: CupertinoColors.destructiveRed,
|
// backgroundColor: CupertinoColors.destructiveRed,
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
@@ -163,6 +181,7 @@ class HomeCaptainController extends GetxController {
|
|||||||
getAllPayment();
|
getAllPayment();
|
||||||
startPeriodicExecution();
|
startPeriodicExecution();
|
||||||
getRefusedOrderByCaptain();
|
getRefusedOrderByCaptain();
|
||||||
|
totalPoints = Get.find<CaptainWalletController>().totalPoints;
|
||||||
super.onInit();
|
super.onInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:get/get.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 '../../../../constant/style.dart';
|
||||||
import '../../../../views/widgets/elevated_btn.dart';
|
import '../../../../views/widgets/elevated_btn.dart';
|
||||||
@@ -15,40 +17,61 @@ class ConnectWidget extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final OrderRequestController orderRequestController =
|
final OrderRequestController orderRequestController =
|
||||||
Get.put(OrderRequestController());
|
Get.put(OrderRequestController());
|
||||||
|
CaptainWalletController captainWalletController =
|
||||||
|
Get.put(CaptainWalletController());
|
||||||
|
|
||||||
|
captainWalletController.getCaptainWalletFromBuyPoints();
|
||||||
return Center(
|
return Center(
|
||||||
child: GetBuilder<HomeCaptainController>(
|
child: GetBuilder<HomeCaptainController>(
|
||||||
builder: (homeCaptainController) =>
|
builder: (homeCaptainController) => int.parse(
|
||||||
int.parse(orderRequestController.countRefuse) > 3
|
orderRequestController.countRefuse) >
|
||||||
? CupertinoButton(
|
3 ||
|
||||||
child: Text('You are Stopped'.tr),
|
double.parse(captainWalletController.totalPoints) < -100
|
||||||
onPressed: () {
|
? CupertinoButton(
|
||||||
Get.defaultDialog(
|
onPressed: () {
|
||||||
// backgroundColor: CupertinoColors.destructiveRed,
|
Get.defaultDialog(
|
||||||
barrierDismissible: false,
|
// backgroundColor: CupertinoColors.destructiveRed,
|
||||||
title: 'You Are Stopped For this Day !'.tr,
|
barrierDismissible: false,
|
||||||
content: Text(
|
title: double.parse(captainWalletController.totalPoints) <
|
||||||
'You Refused 3 Rides this Day that is the reason \nSee you Tomorrow!'
|
-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,
|
.tr,
|
||||||
style: AppStyle.title,
|
style: AppStyle.title,
|
||||||
),
|
),
|
||||||
confirm: MyElevatedButton(
|
confirm:
|
||||||
title: 'Ok , See you Tomorrow'.tr,
|
double.parse(captainWalletController.totalPoints) <
|
||||||
onPressed: () {
|
-100
|
||||||
Get.back();
|
? MyElevatedButton(
|
||||||
Get.back();
|
title: 'Charge your Account'.tr,
|
||||||
}));
|
onPressed: () {
|
||||||
},
|
homeCaptainController
|
||||||
color: CupertinoColors.destructiveRed,
|
.goToWalletFromConnect();
|
||||||
)
|
})
|
||||||
: CupertinoButton(
|
: MyElevatedButton(
|
||||||
child: Text(homeCaptainController.isActive
|
title: 'Ok , See you Tomorrow'.tr,
|
||||||
? 'Connected'.tr
|
onPressed: () {
|
||||||
: 'Not Connected'.tr),
|
Get.back();
|
||||||
onPressed: homeCaptainController.onButtonSelected,
|
Get.back();
|
||||||
color: homeCaptainController.isActive
|
}));
|
||||||
? CupertinoColors.activeGreen
|
},
|
||||||
: CupertinoColors.inactiveGray,
|
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/controller/functions/crud.dart';
|
||||||
import 'package:ride/main.dart';
|
import 'package:ride/main.dart';
|
||||||
|
|
||||||
|
import '../../../views/home/my_wallet/walet_captain.dart';
|
||||||
|
|
||||||
class CaptainWalletController extends GetxController {
|
class CaptainWalletController extends GetxController {
|
||||||
bool isLoading = false;
|
bool isLoading = false;
|
||||||
Map walletDate = {};
|
Map walletDate = {};
|
||||||
|
|||||||
@@ -145,13 +145,11 @@ class HomeCaptain extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'Active Duration:'.tr +
|
'${'Active Duration:'.tr} ${homeCaptainController.stringActiveDuration} ',
|
||||||
' ${homeCaptainController.stringActiveDuration} ',
|
|
||||||
style: AppStyle.title,
|
style: AppStyle.title,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
'Total Connection Duration:'.tr +
|
'${'Total Connection Duration:'.tr} ${homeCaptainController.totalDurationToday} ',
|
||||||
' ${homeCaptainController.totalDurationToday} ',
|
|
||||||
style: AppStyle.title,
|
style: AppStyle.title,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user