9/25/1
This commit is contained in:
@@ -26,4 +26,5 @@ class BoxName {
|
||||
static const String passengerWalletDetails = "passengerWalletDetails";
|
||||
static const String passengerWalletTotal = "passengerWalletTotal";
|
||||
static const String passengerWalletFound = "passengerWalletFound";
|
||||
static const String periods = 'periods';
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -74,7 +74,7 @@ class MyApp extends StatelessWidget {
|
||||
: box.read(BoxName.emailDriver) == null
|
||||
? LoginPage()
|
||||
: box.read(BoxName.emailDriver) != null
|
||||
? const HomeCaptin()
|
||||
? const HomeCaptain()
|
||||
: LoginCaptin());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:ride/constant/credential.dart';
|
||||
import 'package:ride/constant/box_name.dart';
|
||||
import 'package:ride/constant/colors.dart';
|
||||
import 'package:ride/constant/style.dart';
|
||||
import 'package:ride/controller/home/captin/home_captain_controller.dart';
|
||||
import 'package:ride/main.dart';
|
||||
|
||||
import '../../../controller/functions/locaton_controller.dart';
|
||||
import '../../widgets/my_scafold.dart';
|
||||
import '../../../controller/functions/location_controller.dart';
|
||||
import '../../../controller/home/captin/widget/connect.dart';
|
||||
|
||||
class HomeCaptin extends StatelessWidget {
|
||||
const HomeCaptin({super.key});
|
||||
class HomeCaptain extends StatelessWidget {
|
||||
const HomeCaptain({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Get.put(LocationController());
|
||||
return MyScafolld(
|
||||
title: 'Captin Home'.tr,
|
||||
action: GetBuilder<LocationController>(
|
||||
builder: (locationController) => locationController.isloading
|
||||
? const SizedBox(
|
||||
height: 1,
|
||||
width: 1,
|
||||
child: CircularProgressIndicator.adaptive())
|
||||
: const SizedBox(),
|
||||
),
|
||||
body: [
|
||||
|
||||
Get.put(HomeCaptainController());
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: AppColor.blueColor,
|
||||
title: Text('Captain Home'.tr),
|
||||
actions: [
|
||||
GetBuilder<LocationController>(
|
||||
builder: (locationController) => locationController.isLoading
|
||||
? const SizedBox(
|
||||
height: 1,
|
||||
width: 1,
|
||||
child: CircularProgressIndicator.adaptive())
|
||||
: const SizedBox(),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () => box.remove(BoxName.periods),
|
||||
icon: Icon(Icons.remove))
|
||||
],
|
||||
),
|
||||
drawer: const Drawer(),
|
||||
body: Column(
|
||||
children: [
|
||||
GetBuilder<LocationController>(
|
||||
builder: (locationController) => Column(
|
||||
children: [
|
||||
@@ -32,7 +47,7 @@ class HomeCaptin extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'${locationController.mylocation}',
|
||||
'${locationController.myLocation}',
|
||||
style: AppStyle.subtitle,
|
||||
),
|
||||
Text(
|
||||
@@ -42,17 +57,46 @@ class HomeCaptin extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
MyClass().exampleUsage();
|
||||
},
|
||||
child: Text(
|
||||
"Text Button",
|
||||
),
|
||||
),
|
||||
// TextButton(
|
||||
// onPressed: () {
|
||||
// MyClass().exampleUsage();
|
||||
// },
|
||||
// child: Text(
|
||||
// "Text Button",
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
))
|
||||
)),
|
||||
const ConnectWidget(),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Container(
|
||||
decoration: AppStyle.boxDecoration,
|
||||
width: Get.width * .8,
|
||||
height: 80,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'You Earn today is '.tr, //Todo add here number for income
|
||||
style: AppStyle.title,
|
||||
)),
|
||||
),
|
||||
GetBuilder<HomeCaptainController>(
|
||||
builder: (homeCaptainController) => Column(
|
||||
children: [
|
||||
Text(
|
||||
'Active Duration: ${homeCaptainController.activeDuration.inSeconds} seconds',
|
||||
style: const TextStyle(fontSize: 20),
|
||||
),
|
||||
Text(
|
||||
'Total Duration: ${homeCaptainController.calculateTotalDuration()} seconds',
|
||||
style: const TextStyle(fontSize: 20),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
isleading: false);
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user