fixed position error and added goad condition button

This commit is contained in:
2024-03-05 19:32:42 +05:30
parent 773650be82
commit 2f329669e9
4 changed files with 71 additions and 52 deletions

View File

@ -562,6 +562,8 @@ class DestinationController extends GetxController {
} }
Future<void> addGPStoDB(double la, double ln, {isCheckin = 0}) async { Future<void> addGPStoDB(double la, double ln, {isCheckin = 0}) async {
//print("in addGPStoDB ${indexController.currentUser}");
try {
GpsDatabaseHelper db = GpsDatabaseHelper.instance; GpsDatabaseHelper db = GpsDatabaseHelper.instance;
final team_name = indexController.currentUser[0]["user"]['team_name']; final team_name = indexController.currentUser[0]["user"]['team_name'];
final event_code = indexController.currentUser[0]["user"]["event_code"]; final event_code = indexController.currentUser[0]["user"]["event_code"];
@ -574,7 +576,10 @@ class DestinationController extends GetxController {
is_checkin: isCheckin, is_checkin: isCheckin,
created_at: DateTime.now().millisecondsSinceEpoch); created_at: DateTime.now().millisecondsSinceEpoch);
var res = await db.insertGps(gps_data); var res = await db.insertGps(gps_data);
//print("==gps res == ${res}"); } catch (err) {
print("errr ready gps ${err}");
return;
}
} }
Future<void> checkForCheckin() async { Future<void> checkForCheckin() async {
@ -762,6 +767,7 @@ class DestinationController extends GetxController {
} }
void handleLocationUpdate(Position? position) async { void handleLocationUpdate(Position? position) async {
try {
if (position != null) { if (position != null) {
if (distanceToStart() >= 1000) { if (distanceToStart() >= 1000) {
ready_for_goal = true; ready_for_goal = true;
@ -772,6 +778,7 @@ class DestinationController extends GetxController {
LengthUnit.Meter, LengthUnit.Meter,
LatLng(position.latitude, position.longitude), LatLng(position.latitude, position.longitude),
LatLng(currentLat, currentLon)); LatLng(currentLat, currentLon));
Duration difference = Duration difference =
lastGPSCollectedTime.difference(DateTime.now()).abs(); lastGPSCollectedTime.difference(DateTime.now()).abs();
if (difference.inSeconds >= 10 || distanceToDest >= 10) { if (difference.inSeconds >= 10 || distanceToDest >= 10) {
@ -780,17 +787,20 @@ class DestinationController extends GetxController {
LogManager().addLog( LogManager().addLog(
"GPS : $currentLat, $currentLon - ${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}:${DateTime.now().microsecond}"); "GPS : $currentLat, $currentLon - ${DateTime.now().hour}:${DateTime.now().minute}:${DateTime.now().second}:${DateTime.now().microsecond}");
if (isInRog.value) { if (isInRog.value) {
await addGPStoDB(position.latitude, position.longitude); await addGPStoDB(position.latitude, position.longitude);
lastGPSCollectedTime = DateTime.now(); lastGPSCollectedTime = DateTime.now();
} }
} }
}
} finally {
if (position != null &&
(position.latitude != 0 || position.longitude != 0)) {
currentLat = position.latitude; currentLat = position.latitude;
currentLon = position.longitude; currentLon = position.longitude;
} }
} }
}
double distanceToStart() { double distanceToStart() {
if (indexController.locations.isEmpty) { if (indexController.locations.isEmpty) {
@ -908,8 +918,11 @@ class DestinationController extends GetxController {
} }
void centerMapToCurrentLocation() { void centerMapToCurrentLocation() {
print("center is ${currentLat}, ${currentLon}");
if (currentLat != 0 || currentLon != 0) {
indexController.mapController.move(LatLng(currentLat, currentLon), 17.0); indexController.mapController.move(LatLng(currentLat, currentLon), 17.0);
} }
}
void connectionChanged(String val) { void connectionChanged(String val) {
//print('----- %%%%%%%%%%%%%%%%%%%%% ----- $val'); //print('----- %%%%%%%%%%%%%%%%%%%%% ----- $val');

View File

@ -44,20 +44,26 @@ class GpsDatabaseHelper {
} }
Future<int> insertGps(GpsData gps) async { Future<int> insertGps(GpsData gps) async {
try {
print("---- try insering ${gps.toMap()}");
Database db = await instance.database; Database db = await instance.database;
int? nextOrder = int? nextOrder =
Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(id) FROM gps')); Sqflite.firstIntValue(await db.rawQuery('SELECT MAX(id) FROM gps'));
nextOrder = nextOrder ?? 0; nextOrder = nextOrder ?? 0;
nextOrder = nextOrder + 1; nextOrder = nextOrder + 1;
gps.id = nextOrder; gps.id = nextOrder;
//print("---- insering ${gps.toMap()}"); print("---- insering ${gps.toMap()}");
int res = await db.insert( int res = await db.insert(
'gps', 'gps',
gps.toMap(), gps.toMap(),
conflictAlgorithm: ConflictAlgorithm.replace, conflictAlgorithm: ConflictAlgorithm.replace,
); );
//print("------ database helper insert $res-----------::::::::"); print("------ database helper insert $res-----------::::::::");
return res; return res;
} catch (err) {
print("------ error $err-----------::::::::");
return -1;
}
} }
Future<List<GpsData>> getGPSData(String team_name, String event_code) async { Future<List<GpsData>> getGPSData(String team_name, String event_code) async {

View File

@ -129,7 +129,7 @@ class BottomSheetNew extends GetView<BottomSheetController> {
style: ElevatedButton.styleFrom(backgroundColor: Colors.red), style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: destinationController.rogainingCounted.value == true && onPressed: destinationController.rogainingCounted.value == true &&
destinationController.distanceToStart() <= 500 && destinationController.distanceToStart() <= 500 &&
//destination.cp == -1 && destination.cp == -1 &&
DestinationController.ready_for_goal == true DestinationController.ready_for_goal == true
? () async { ? () async {
destinationController.isAtGoal.value = true; destinationController.isAtGoal.value = true;

View File

@ -176,7 +176,7 @@ class _MapWidgetState extends State<MapWidget> {
} }
void _centerMapOnUser() { void _centerMapOnUser() {
print("showBottomSheet ${destinationController.shouldShowBottomSheet}"); //print("showBottomSheet ${destinationController.shouldShowBottomSheet}");
if (destinationController.shouldShowBottomSheet) { if (destinationController.shouldShowBottomSheet) {
destinationController.centerMapToCurrentLocation(); destinationController.centerMapToCurrentLocation();
} }