9/25/1
This commit is contained in:
@@ -26,4 +26,5 @@ class BoxName {
|
|||||||
static const String passengerWalletDetails = "passengerWalletDetails";
|
static const String passengerWalletDetails = "passengerWalletDetails";
|
||||||
static const String passengerWalletTotal = "passengerWalletTotal";
|
static const String passengerWalletTotal = "passengerWalletTotal";
|
||||||
static const String passengerWalletFound = "passengerWalletFound";
|
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']);
|
box.write(BoxName.phoneDriver, jsonDecoeded['data'][0]['phone']);
|
||||||
SecureStorage()
|
SecureStorage()
|
||||||
.saveData(BoxName.passwordDriver, passwordController.text);
|
.saveData(BoxName.passwordDriver, passwordController.text);
|
||||||
Get.offAll(() => const HomeCaptin());
|
Get.offAll(() => const HomeCaptain());
|
||||||
isloading = false;
|
isloading = false;
|
||||||
update();
|
update();
|
||||||
print(box.read(BoxName.driverID).toString());
|
print(box.read(BoxName.driverID).toString());
|
||||||
@@ -101,7 +101,7 @@ class LoginCaptinController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loginByBoxData() async {
|
void loginByBoxData() async {
|
||||||
Get.to(() => const HomeCaptin());
|
Get.to(() => const HomeCaptain());
|
||||||
await CRUD().post(link: AppLink.addTokensDriver, payload: {
|
await CRUD().post(link: AppLink.addTokensDriver, payload: {
|
||||||
'token': box.read(BoxName.tokenDriver).toString(),
|
'token': box.read(BoxName.tokenDriver).toString(),
|
||||||
'captain_id': box.read(BoxName.driverID).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/controller/functions/crud.dart';
|
||||||
import 'package:ride/main.dart';
|
import 'package:ride/main.dart';
|
||||||
|
|
||||||
|
import '../home/captin/home_captain_controller.dart';
|
||||||
|
|
||||||
|
// LocationController.dart
|
||||||
class LocationController extends GetxController {
|
class LocationController extends GetxController {
|
||||||
LocationData? _currentLocation;
|
LocationData? _currentLocation;
|
||||||
late Location location;
|
late Location location;
|
||||||
bool isloading = false;
|
bool isLoading = false;
|
||||||
LatLng mylocation = const LatLng(32.3, 36.3);
|
LatLng myLocation = const LatLng(32.3, 36.3);
|
||||||
|
|
||||||
LocationData? get currentLocation => _currentLocation;
|
LocationData? get currentLocation => _currentLocation;
|
||||||
Timer? _locationTimer;
|
Timer? _locationTimer;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() async {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
|
await CRUD().post(link: AppLink.addTokensDriver, payload: {
|
||||||
|
'token': box.read(BoxName.tokenDriver),
|
||||||
|
'captain_id': box.read(BoxName.driverID).toString()
|
||||||
|
});
|
||||||
location = Location();
|
location = Location();
|
||||||
getLocation();
|
getLocation();
|
||||||
startLocationUpdates();
|
startLocationUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
void startLocationUpdates() async {
|
void startLocationUpdates() async {
|
||||||
|
// if (Get.find<HomeCaptainController>().isActive) {
|
||||||
// Start the timer to get location every 20 seconds
|
// Start the timer to get location every 20 seconds
|
||||||
_locationTimer = Timer.periodic(const Duration(seconds: 20), (timer) async {
|
_locationTimer = Timer.periodic(const Duration(seconds: 20), (timer) async {
|
||||||
await getLocation();
|
await getLocation();
|
||||||
|
|
||||||
await CRUD().post(link: AppLink.addCarsLocationByPassenger, payload: {
|
await CRUD().post(link: AppLink.addCarsLocationByPassenger, payload: {
|
||||||
'driver_id': box.read(BoxName.driverID).toString(),
|
'driver_id': box.read(BoxName.driverID).toString(),
|
||||||
'latitude': mylocation.latitude.toString(),
|
'latitude': myLocation.latitude.toString(),
|
||||||
'longitude': mylocation.longitude.toString(),
|
'longitude': myLocation.longitude.toString(),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getLocation() async {
|
Future<void> getLocation() async {
|
||||||
isloading = true;
|
isLoading = true;
|
||||||
update();
|
update();
|
||||||
bool serviceEnabled;
|
bool serviceEnabled;
|
||||||
PermissionStatus permissionGranted;
|
PermissionStatus permissionGranted;
|
||||||
@@ -68,7 +78,7 @@ class LocationController extends GetxController {
|
|||||||
|
|
||||||
// Get the current location
|
// Get the current location
|
||||||
LocationData _locationData = await location.getLocation();
|
LocationData _locationData = await location.getLocation();
|
||||||
mylocation =
|
myLocation =
|
||||||
(_locationData.latitude != null && _locationData.longitude != null
|
(_locationData.latitude != null && _locationData.longitude != null
|
||||||
? LatLng(_locationData.latitude!, _locationData.longitude!)
|
? LatLng(_locationData.latitude!, _locationData.longitude!)
|
||||||
: null)!;
|
: null)!;
|
||||||
@@ -78,7 +88,7 @@ class LocationController extends GetxController {
|
|||||||
print('Latitude: ${_locationData.latitude}');
|
print('Latitude: ${_locationData.latitude}');
|
||||||
print('Longitude: ${_locationData.longitude}');
|
print('Longitude: ${_locationData.longitude}');
|
||||||
print('Time: ${_locationData.time}');
|
print('Time: ${_locationData.time}');
|
||||||
isloading = false;
|
isLoading = false;
|
||||||
update();
|
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 {
|
void timerEnded() async {
|
||||||
print('Timer ended');
|
print('Timer ended');
|
||||||
|
|
||||||
runEvery50SecondsUntilConditionMet();
|
runEvery50SecondsUntilConditionMet();
|
||||||
isCancelRidePageShown = false;
|
isCancelRidePageShown = false;
|
||||||
update();
|
update();
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class MyApp extends StatelessWidget {
|
|||||||
: box.read(BoxName.emailDriver) == null
|
: box.read(BoxName.emailDriver) == null
|
||||||
? LoginPage()
|
? LoginPage()
|
||||||
: box.read(BoxName.emailDriver) != null
|
: box.read(BoxName.emailDriver) != null
|
||||||
? const HomeCaptin()
|
? const HomeCaptain()
|
||||||
: LoginCaptin());
|
: LoginCaptin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,43 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.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/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 '../../../controller/functions/location_controller.dart';
|
||||||
import '../../widgets/my_scafold.dart';
|
import '../../../controller/home/captin/widget/connect.dart';
|
||||||
|
|
||||||
class HomeCaptin extends StatelessWidget {
|
class HomeCaptain extends StatelessWidget {
|
||||||
const HomeCaptin({super.key});
|
const HomeCaptain({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Get.put(LocationController());
|
Get.put(LocationController());
|
||||||
return MyScafolld(
|
|
||||||
title: 'Captin Home'.tr,
|
Get.put(HomeCaptainController());
|
||||||
action: GetBuilder<LocationController>(
|
return Scaffold(
|
||||||
builder: (locationController) => locationController.isloading
|
appBar: AppBar(
|
||||||
? const SizedBox(
|
backgroundColor: AppColor.blueColor,
|
||||||
height: 1,
|
title: Text('Captain Home'.tr),
|
||||||
width: 1,
|
actions: [
|
||||||
child: CircularProgressIndicator.adaptive())
|
GetBuilder<LocationController>(
|
||||||
: const SizedBox(),
|
builder: (locationController) => locationController.isLoading
|
||||||
),
|
? const SizedBox(
|
||||||
body: [
|
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>(
|
GetBuilder<LocationController>(
|
||||||
builder: (locationController) => Column(
|
builder: (locationController) => Column(
|
||||||
children: [
|
children: [
|
||||||
@@ -32,7 +47,7 @@ class HomeCaptin extends StatelessWidget {
|
|||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
'${locationController.mylocation}',
|
'${locationController.myLocation}',
|
||||||
style: AppStyle.subtitle,
|
style: AppStyle.subtitle,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
@@ -42,17 +57,46 @@ class HomeCaptin extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
TextButton(
|
// TextButton(
|
||||||
onPressed: () {
|
// onPressed: () {
|
||||||
MyClass().exampleUsage();
|
// MyClass().exampleUsage();
|
||||||
},
|
// },
|
||||||
child: Text(
|
// child: Text(
|
||||||
"Text Button",
|
// "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