fixed checkin issue

This commit is contained in:
Mohamed Nouffer
2023-09-12 12:57:45 +05:30
parent d67d17e971
commit 48f4b833f6
4 changed files with 120 additions and 90 deletions

View File

@ -85,6 +85,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
restoreGame(); restoreGame();
if(destinationController.positionStream == null){ if(destinationController.positionStream == null){
destinationController.startGPSTimer(); destinationController.startGPSTimer();
destinationController.startGame();
} }
break; break;
case AppLifecycleState.inactive: case AppLifecycleState.inactive:

View File

@ -48,6 +48,9 @@ class CameraPage extends StatelessWidget {
backgroundColor: Colors.red backgroundColor: Colors.red
), ),
onPressed: () async { onPressed: () async {
print("----- user isss ${indexController.currentUser[0]} -----");
settingGoal.value = true; settingGoal.value = true;
try{ try{
int userId = indexController.currentUser[0]["user"]["id"]; int userId = indexController.currentUser[0]["user"]["id"];

View File

@ -113,7 +113,7 @@ class DestinationController extends GetxController {
print("---- is in rog is ${is_in_rog} ----"); print("---- is in rog is ${is_in_rog} ----");
//skip_gps = true; //skip_gps = true;
double checkinRadious = fs.properties!['checkin_radius'] ?? double.infinity; double checkinRadious = fs.properties!['checkin_radius'] ?? double.infinity;
//if (checkinRadious >= distance) { if (checkinRadious >= distance) {
indexController.currentFeature.clear(); indexController.currentFeature.clear();
Destination d = festuretoDestination(fs); Destination d = festuretoDestination(fs);
print("----- destination lenght is ${destinations.length} -----"); print("----- destination lenght is ${destinations.length} -----");
@ -126,7 +126,8 @@ class DestinationController extends GetxController {
indexController.currentFeature.add(fs); indexController.currentFeature.add(fs);
print("---- before calling startTimer ----"); print("---- before calling startTimer ----");
startTimer(d, distance); startTimer(d, distance);
//} return;
}
} }
void startTimer(Destination d, double distance) async { void startTimer(Destination d, double distance) async {
@ -139,7 +140,8 @@ class DestinationController extends GetxController {
double checkinRadious = d.checkin_radious ?? double.infinity; double checkinRadious = d.checkin_radious ?? double.infinity;
bool autoCheckin = d.auto_checkin == 0 ? false : true; bool autoCheckin = d.auto_checkin == 0 ? false : true;
bool locationAlreadyCheckedIn = ds.length > 0 && ds[0].checkedin == true ? true : false; bool locationAlreadyCheckedIn =
ds.length > 0 && ds[0].checkedin == true ? true : false;
bool isuserLoggedIn = indexController.currentUser.isNotEmpty ? true : false; bool isuserLoggedIn = indexController.currentUser.isNotEmpty ? true : false;
//make current destination //make current destination
print("---- checkin_radious $checkinRadious ----"); print("---- checkin_radious $checkinRadious ----");
@ -159,9 +161,7 @@ class DestinationController extends GetxController {
if (is_photo_shoot.value == true) { if (is_photo_shoot.value == true) {
photos.clear(); photos.clear();
showModalBottomSheet( showModalBottomSheet(
constraints: BoxConstraints.loose(Size( constraints: BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
Get.width,
Get.height * 0.75)),
context: Get.context!, context: Get.context!,
isScrollControlled: true, isScrollControlled: true,
builder: ((context) => CameraPage())).whenComplete(() { builder: ((context) => CameraPage())).whenComplete(() {
@ -182,9 +182,8 @@ class DestinationController extends GetxController {
is_in_checkin.value = true; is_in_checkin.value = true;
is_at_start.value = true; is_at_start.value = true;
showModalBottomSheet( showModalBottomSheet(
constraints: BoxConstraints.loose(Size( constraints:
Get.width, BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
Get.height * 0.75)),
context: Get.context!, context: Get.context!,
isScrollControlled: true, isScrollControlled: true,
builder: ((context) => BottomSheetNew())).whenComplete(() { builder: ((context) => BottomSheetNew())).whenComplete(() {
@ -198,9 +197,8 @@ class DestinationController extends GetxController {
chekcs = 2; chekcs = 2;
is_in_checkin.value = true; is_in_checkin.value = true;
showModalBottomSheet( showModalBottomSheet(
constraints: BoxConstraints.loose(Size( constraints:
Get.width, BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
Get.height * 0.75)),
context: Get.context!, context: Get.context!,
isScrollControlled: true, isScrollControlled: true,
builder: ((context) => BottomSheetNew())).whenComplete(() { builder: ((context) => BottomSheetNew())).whenComplete(() {
@ -237,9 +235,8 @@ class DestinationController extends GetxController {
is_in_checkin.value = true; is_in_checkin.value = true;
photos.clear(); photos.clear();
showModalBottomSheet( showModalBottomSheet(
constraints: BoxConstraints.loose(Size( constraints:
Get.width, BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
Get.height * 0.75)),
context: Get.context!, context: Get.context!,
isScrollControlled: true, isScrollControlled: true,
builder: ((context) => CameraPage( builder: ((context) => CameraPage(
@ -290,9 +287,8 @@ class DestinationController extends GetxController {
is_at_goal.value = true; is_at_goal.value = true;
photos.clear(); photos.clear();
showModalBottomSheet( showModalBottomSheet(
constraints: BoxConstraints.loose(Size( constraints:
Get.width, BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
Get.height * 0.75)),
context: Get.context!, context: Get.context!,
isScrollControlled: true, isScrollControlled: true,
builder: ((context) => CameraPage( builder: ((context) => CameraPage(
@ -310,9 +306,8 @@ class DestinationController extends GetxController {
chekcs = 6; chekcs = 6;
is_at_start.value = true; is_at_start.value = true;
showModalBottomSheet( showModalBottomSheet(
constraints: BoxConstraints.loose(Size( constraints:
Get.width, BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
Get.height * 0.75)),
context: Get.context!, context: Get.context!,
isScrollControlled: true, isScrollControlled: true,
builder: ((context) => BottomSheetNew())).whenComplete(() { builder: ((context) => BottomSheetNew())).whenComplete(() {
@ -327,6 +322,7 @@ class DestinationController extends GetxController {
if (chekcs == 0) { if (chekcs == 0) {
skip_gps = false; skip_gps = false;
} }
return;
} }
void resetRogaining() async { void resetRogaining() async {
@ -355,6 +351,7 @@ class DestinationController extends GetxController {
db.deleteAllDestinations().then((value) { db.deleteAllDestinations().then((value) {
PopulateDestinations(); PopulateDestinations();
startGPSTimer(); startGPSTimer();
startGame();
//initGPS(); //initGPS();
}); });
@ -376,9 +373,7 @@ class DestinationController extends GetxController {
print("----image file is : $file----"); print("----image file is : $file----");
//setState(() {}); //setState(() {});
}, },
) )));
));
} }
void getRoutePoints() { void getRoutePoints() {
@ -424,9 +419,8 @@ class DestinationController extends GetxController {
is_in_checkin.value = true; is_in_checkin.value = true;
photos.clear(); photos.clear();
showModalBottomSheet( showModalBottomSheet(
constraints: BoxConstraints.loose(Size( constraints:
Get.width, BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
Get.height * 0.75)),
context: Get.context!, context: Get.context!,
isScrollControlled: true, isScrollControlled: true,
builder: ((context) => CameraPage( builder: ((context) => CameraPage(
@ -443,39 +437,14 @@ class DestinationController extends GetxController {
} }
} }
void checkForCheckin(double la, double ln) { void checkForCheckin() async {
print("--- skip_gps ---- $skip_gps----"); print("--- Start of checkForCheckin function ---");
// for (final d in destinations) { try {
// print("--- check checkin for--loc_id- ${d.sub_loc_id}----"); print("--- 000 ---- $skip_gps----");
await Future.delayed(const Duration(milliseconds: 1500));
// double lat = d.lat!; final la = current_lat;
// double lon = d.lon!; final ln = current_lon;
// LatLng p = LatLng(lat, lon);
// getDestinationForLatLong(lat, lon).then((value) {
// var distance = const Distance();
// double dist =
// distance.as(LengthUnit.Meter, LatLng(lat, lon), LatLng(la, ln));
// //double checkin_radious = value!.checkin_radious ?? double.infinity;
// //bool auto_checkin = value.auto_checkin == 0 ? false : true;
// //bool location_already_checked_id = d.checkedin ?? false;
// // print("-----rogaining_counted---${rogaining_counted.value}-----");
// // print("-----is_in_rog---${is_in_rog}-----");
// // print("-----dist is ---${dist}-----");
// //print("----- ${indexController.currentUser} ----");
// if (dist <= 250 && skip_gps == false) {
// //near a destination
// print("---- time with ${d.location_id} ----");
// startTimer(d, dist);
// }
// });
// }
if (indexController.locations.isEmpty) return;
//check for location in bounds
for (GeoJsonFeature fs in indexController.locations[0].collection) { for (GeoJsonFeature fs in indexController.locations[0].collection) {
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint; GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude,
@ -483,18 +452,71 @@ class DestinationController extends GetxController {
double latFs = pt.latitude; double latFs = pt.latitude;
double lonFs = pt.longitude; double lonFs = pt.longitude;
LatLng pFs = LatLng(latFs, lonFs);
var distanceFs = const Distance(); var distanceFs = const Distance();
double distFs = double distFs = distanceFs.as(
distanceFs.as(LengthUnit.Meter, LatLng(latFs, lonFs), LatLng(la, ln)); LengthUnit.Meter, LatLng(latFs, lonFs), LatLng(la, ln));
if (distFs <= 250 && skip_gps == false) { if (distFs <= 250 && skip_gps == false) {
print("--- 789 ---- $skip_gps----");
//near a location //near a location
print("---- before call startTimerLocation ----"); print("---- before call startTimerLocation ----");
startTimerLocation(fs, distFs); startTimerLocation(fs, distFs);
} }
} }
print("--- 123 ---- $skip_gps----");
} catch (e) {
print("An error occurred: $e");
} finally {
print("--- End of checkForCheckin function, calling recursively ---");
checkForCheckin();
} }
}
// void checkForCheckin() async {
// final la = current_lat;
// final ln = current_lon;
// print("--- in checkForCheckin ----");
// // if (indexController.locations.isEmpty){
// // await Future.delayed(const Duration(seconds: 2));
// // checkForCheckin();
// // return;
// // }
// print("--- 123 ---- $skip_gps----");
// //check for location in bounds
// for (GeoJsonFeature fs in indexController.locations[0].collection) {
// try {
// await Future.delayed(const Duration(seconds: 2000));
// GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
// LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude,
// mp.geoSerie!.geoPoints[0].longitude);
// print("--- 456 ---- $skip_gps----");
// double latFs = pt.latitude;
// double lonFs = pt.longitude;
// LatLng pFs = LatLng(latFs, lonFs);
// var distanceFs = const Distance();
// double distFs = distanceFs.as(
// LengthUnit.Meter, LatLng(latFs, lonFs), LatLng(la, ln));
// if (distFs <= 250 && skip_gps == false) {
// print("--- 789 ---- $skip_gps----");
// //near a location
// print("---- before call startTimerLocation ----");
// startTimerLocation(fs, distFs);
// }
// } catch (e) {
// print("----- error -----");
// } finally {
// print("--- 101112 ----");
// checkForCheckin();
// }
// }
// //await Future.delayed(const Duration(seconds: 3));
// }
void addToRogaining(double lat, double lon, int destinationId) async { void addToRogaining(double lat, double lon, int destinationId) async {
DatabaseHelper db = DatabaseHelper.instance; DatabaseHelper db = DatabaseHelper.instance;
@ -588,7 +610,8 @@ class DestinationController extends GetxController {
} }
try { try {
positionStream = Geolocator.getPositionStream(locationSettings: locationSettings) positionStream =
Geolocator.getPositionStream(locationSettings: locationSettings)
.listen((Position? position) { .listen((Position? position) {
current_lat = position != null ? position.latitude : 0; current_lat = position != null ? position.latitude : 0;
current_lon = position != null ? position.longitude : 0; current_lon = position != null ? position.longitude : 0;
@ -609,7 +632,7 @@ class DestinationController extends GetxController {
//gps.clear(); //gps.clear();
//gps.add( //gps.add(
// "-- lat : ${position.latitude}, lon : ${position.longitude} --"); // "-- lat : ${position.latitude}, lon : ${position.longitude} --");
checkForCheckin(position.latitude, position.longitude); //checkForCheckin(position.latitude, position.longitude);
print("--- call check checkin"); print("--- call check checkin");
print("---- skip gps is ${skip_gps.toString()} ----"); print("---- skip gps is ${skip_gps.toString()} ----");
//}); //});
@ -624,14 +647,14 @@ class DestinationController extends GetxController {
ever(indexController.connectionStatusName, connectionChanged); ever(indexController.connectionStatusName, connectionChanged);
} }
void startGPSTimer() { void startGPSTimer() {
// If a timer is already running, we first cancel it // If a timer is already running, we first cancel it
_GPStimer?.cancel(); _GPStimer?.cancel();
// Start a new timer that fires every 3 seconds // Start a new timer that fires every 3 seconds
_timer = Timer.periodic(Duration(seconds: 3), (timer) async { _timer = Timer.periodic(Duration(seconds: 3), (timer) async {
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
current_lat = position.latitude; current_lat = position.latitude;
current_lon = position.longitude; current_lon = position.longitude;
@ -639,7 +662,7 @@ class DestinationController extends GetxController {
double czoom = indexController.rogMapController.zoom; double czoom = indexController.rogMapController.zoom;
indexController.rogMapController indexController.rogMapController
.move(LatLng(position.latitude, position.longitude), czoom); .move(LatLng(position.latitude, position.longitude), czoom);
checkForCheckin(position.latitude, position.longitude); //checkForCheckin(position.latitude, position.longitude);
print("--- call check checkin"); print("--- call check checkin");
print("---- skip gps is ${skip_gps.toString()} ----"); print("---- skip gps is ${skip_gps.toString()} ----");
} }
@ -650,7 +673,9 @@ class DestinationController extends GetxController {
_GPStimer?.cancel(); _GPStimer?.cancel();
} }
void startGame() {
checkForCheckin();
}
@override @override
void onClose() { void onClose() {
@ -664,6 +689,7 @@ class DestinationController extends GetxController {
void onInit() async { void onInit() async {
//initGPS(); //initGPS();
startGPSTimer(); startGPSTimer();
startGame();
super.onInit(); super.onInit();
} }

View File

@ -136,7 +136,7 @@ class AuthService{
cats = json.decode(utf8.decode(response.bodyBytes)); cats = json.decode(utf8.decode(response.bodyBytes));
print("--- eeeeee $cats ----"); print("--- eeeeee $cats ----");
} }
return [{"user":cats}]; return [{"user":cats, "token":token}];
} }