9/25/1
This commit is contained in:
@@ -60,7 +60,7 @@ class LoginCaptinController extends GetxController {
|
||||
box.write(BoxName.phoneDriver, jsonDecoeded['data'][0]['phone']);
|
||||
SecureStorage()
|
||||
.saveData(BoxName.passwordDriver, passwordController.text);
|
||||
Get.offAll(() => const HomeCaptin());
|
||||
Get.offAll(() => const HomeCaptain());
|
||||
isloading = false;
|
||||
update();
|
||||
print(box.read(BoxName.driverID).toString());
|
||||
@@ -101,7 +101,7 @@ class LoginCaptinController extends GetxController {
|
||||
}
|
||||
|
||||
void loginByBoxData() async {
|
||||
Get.to(() => const HomeCaptin());
|
||||
Get.to(() => const HomeCaptain());
|
||||
await CRUD().post(link: AppLink.addTokensDriver, payload: {
|
||||
'token': box.read(BoxName.tokenDriver).toString(),
|
||||
'captain_id': box.read(BoxName.driverID).toString()
|
||||
|
||||
@@ -8,37 +8,47 @@ import 'package:ride/constant/links.dart';
|
||||
import 'package:ride/controller/functions/crud.dart';
|
||||
import 'package:ride/main.dart';
|
||||
|
||||
import '../home/captin/home_captain_controller.dart';
|
||||
|
||||
// LocationController.dart
|
||||
class LocationController extends GetxController {
|
||||
LocationData? _currentLocation;
|
||||
late Location location;
|
||||
bool isloading = false;
|
||||
LatLng mylocation = const LatLng(32.3, 36.3);
|
||||
bool isLoading = false;
|
||||
LatLng myLocation = const LatLng(32.3, 36.3);
|
||||
|
||||
LocationData? get currentLocation => _currentLocation;
|
||||
Timer? _locationTimer;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
await CRUD().post(link: AppLink.addTokensDriver, payload: {
|
||||
'token': box.read(BoxName.tokenDriver),
|
||||
'captain_id': box.read(BoxName.driverID).toString()
|
||||
});
|
||||
location = Location();
|
||||
getLocation();
|
||||
startLocationUpdates();
|
||||
}
|
||||
|
||||
void startLocationUpdates() async {
|
||||
// if (Get.find<HomeCaptainController>().isActive) {
|
||||
// Start the timer to get location every 20 seconds
|
||||
_locationTimer = Timer.periodic(const Duration(seconds: 20), (timer) async {
|
||||
await getLocation();
|
||||
|
||||
await CRUD().post(link: AppLink.addCarsLocationByPassenger, payload: {
|
||||
'driver_id': box.read(BoxName.driverID).toString(),
|
||||
'latitude': mylocation.latitude.toString(),
|
||||
'longitude': mylocation.longitude.toString(),
|
||||
'latitude': myLocation.latitude.toString(),
|
||||
'longitude': myLocation.longitude.toString(),
|
||||
});
|
||||
});
|
||||
// }
|
||||
}
|
||||
|
||||
Future<void> getLocation() async {
|
||||
isloading = true;
|
||||
isLoading = true;
|
||||
update();
|
||||
bool serviceEnabled;
|
||||
PermissionStatus permissionGranted;
|
||||
@@ -68,7 +78,7 @@ class LocationController extends GetxController {
|
||||
|
||||
// Get the current location
|
||||
LocationData _locationData = await location.getLocation();
|
||||
mylocation =
|
||||
myLocation =
|
||||
(_locationData.latitude != null && _locationData.longitude != null
|
||||
? LatLng(_locationData.latitude!, _locationData.longitude!)
|
||||
: null)!;
|
||||
@@ -78,7 +88,7 @@ class LocationController extends GetxController {
|
||||
print('Latitude: ${_locationData.latitude}');
|
||||
print('Longitude: ${_locationData.longitude}');
|
||||
print('Time: ${_locationData.time}');
|
||||
isloading = false;
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
51
lib/controller/home/captin/home_captain_controller.dart
Normal file
51
lib/controller/home/captin/home_captain_controller.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:ride/constant/box_name.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import '../../../main.dart';
|
||||
|
||||
class HomeCaptainController extends GetxController {
|
||||
bool isActive = false;
|
||||
DateTime? activeStartTime;
|
||||
Duration activeDuration = Duration.zero;
|
||||
Timer? activeTimer;
|
||||
|
||||
void onButtonSelected() {
|
||||
isActive = !isActive;
|
||||
if (isActive) {
|
||||
activeStartTime = DateTime.now();
|
||||
activeTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||
activeDuration = DateTime.now().difference(activeStartTime!);
|
||||
update();
|
||||
});
|
||||
} else {
|
||||
activeStartTime = null;
|
||||
activeTimer?.cancel();
|
||||
savePeriod(activeDuration);
|
||||
activeDuration = Duration.zero;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void savePeriod(Duration period) {
|
||||
final periods = box.read<List<dynamic>>(BoxName.periods) ?? [];
|
||||
periods.add(period.inSeconds);
|
||||
box.write(BoxName.periods, periods);
|
||||
}
|
||||
|
||||
Duration calculateTotalDuration() {
|
||||
final periods = box.read<List<dynamic>>(BoxName.periods) ?? [];
|
||||
Duration totalDuration = Duration.zero;
|
||||
for (dynamic periodInSeconds in periods) {
|
||||
final periodDuration = Duration(seconds: periodInSeconds);
|
||||
totalDuration += periodDuration;
|
||||
}
|
||||
return totalDuration;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
activeTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
27
lib/controller/home/captin/widget/connect.dart
Normal file
27
lib/controller/home/captin/widget/connect.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../home_captain_controller.dart';
|
||||
|
||||
class ConnectWidget extends StatelessWidget {
|
||||
const ConnectWidget({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
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,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -233,6 +233,7 @@ class MapController extends GetxController {
|
||||
|
||||
void timerEnded() async {
|
||||
print('Timer ended');
|
||||
|
||||
runEvery50SecondsUntilConditionMet();
|
||||
isCancelRidePageShown = false;
|
||||
update();
|
||||
|
||||
Reference in New Issue
Block a user