From 44cb728fabef7fd9cd3df6fac5c6cf757a11f659 Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Mon, 27 Nov 2023 14:57:25 +0530 Subject: [PATCH] fixed timer issue --- lib/main.dart | 14 +++++----- lib/model/destination.dart | 2 +- lib/pages/camera/camera_page.dart | 2 +- .../destination/destination_controller.dart | 26 ++++++++++++------- lib/pages/gps/gps_page.dart | 2 +- lib/pages/index/index_controller.dart | 2 +- lib/services/external_service.dart | 12 +++++---- lib/services/location_service.dart | 2 +- lib/utils/database_gps.dart | 4 +-- lib/widgets/bottom_sheet_new.dart | 2 +- 10 files changed, 38 insertions(+), 30 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 3e6c841..86c920e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -25,8 +25,8 @@ void restoreGame() async { destinationController.isInRog.value = pref.getBool("is_in_rog") ?? false; destinationController.rogainingCounted.value = pref.getBool("rogaining_counted") ?? false; - print( - "--restored -- destinationController.isInRog.value ${pref.getBool("is_in_rog")} -- ${pref.getBool("rogaining_counted")}"); + //print( + // "--restored -- destinationController.isInRog.value ${pref.getBool("is_in_rog")} -- ${pref.getBool("rogaining_counted")}"); } void main() async { @@ -88,22 +88,22 @@ class _MyAppState extends State with WidgetsBindingObserver { Get.find(); switch (state) { case AppLifecycleState.resumed: - print("RESUMED"); + //print("RESUMED"); restoreGame(); break; case AppLifecycleState.inactive: - print("INACTIVE"); + //print("INACTIVE"); break; case AppLifecycleState.paused: - print("PAUSED"); + //print("PAUSED"); saveGameState(); break; case AppLifecycleState.detached: - print("DETACHED"); + //print("DETACHED"); saveGameState(); break; case AppLifecycleState.hidden: - print("DETACHED"); + //print("DETACHED"); saveGameState(); break; } diff --git a/lib/model/destination.dart b/lib/model/destination.dart index f4242a2..951f55e 100644 --- a/lib/model/destination.dart +++ b/lib/model/destination.dart @@ -61,7 +61,7 @@ class Destination { bool checkin = json['checkedin'] == 0 ? false : true; bool forcedCheckin = json['forced_checkin'] == 0 ? false : true; - print("-----tags model----- ${json}"); + //print("-----tags model----- ${json}"); return Destination( name: json['name'], diff --git a/lib/pages/camera/camera_page.dart b/lib/pages/camera/camera_page.dart index 9569c52..be4e0ff 100644 --- a/lib/pages/camera/camera_page.dart +++ b/lib/pages/camera/camera_page.dart @@ -284,7 +284,7 @@ class CameraPage extends StatelessWidget { @override Widget build(BuildContext context) { - print("---- photos ${destination.photos} ----"); + //print("---- photos ${destination.photos} ----"); if (buyPointPhoto == true) { //print("--- buy point camera ${destination.toString()}"); return BuyPointCamera(destination: destination); diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index 3a1ca98..2ea0e5f 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -37,7 +37,8 @@ class DestinationController extends GetxController { double currentLat = 0.0; double currentLon = 0.0; - bool gps_push_started = false; + static bool gps_push_started = false; + static bool game_started = false; bool skip_10s = false; @@ -125,7 +126,7 @@ class DestinationController extends GetxController { } Future startTimer(Destination d, double distance) async { - print("=== passed dest is ${d.location_id} ${d.checkedin} ===="); + //print("=== passed dest is ${d.location_id} ${d.checkedin} ===="); skipGps = true; //print("---- in startTimer ----"); @@ -514,11 +515,12 @@ class DestinationController extends GetxController { is_checkin: isCheckin, created_at: DateTime.now().millisecondsSinceEpoch); var res = await db.insertGps(gps_data); - print("==gps res == ${res}"); + //print("==gps res == ${res}"); } Future checkForCheckin() async { - print("--- Start of checkForCheckin function ---"); + //print("--- Start of checkForCheckin function ---"); + game_started = true; try { //print("--- 000 ---- $skip_gps----"); @@ -587,15 +589,17 @@ class DestinationController extends GetxController { } Future pushGPStoServer() async { + // print( + // "^^^^^^^^ ${DateFormat('kk:mm:ss \n EEE d MMM').format(DateTime.now())}"); try { - await Future.delayed(const Duration(minutes: 5)); gps_push_started = true; ExternalService().pushGPS(); } catch (e) { //print("An error occurred: $e"); - await pushGPStoServer(); + //await pushGPStoServer(); } finally { //print("--- End of pushGPStoServer function, calling recursively ---"); + await Future.delayed(const Duration(seconds: 5 * 60)); await pushGPStoServer(); } } @@ -702,7 +706,9 @@ class DestinationController extends GetxController { Future startGame() async { //print("------ starting game ------"); - await checkForCheckin(); + if (game_started == false) { + await checkForCheckin(); + } } @override @@ -718,13 +724,13 @@ class DestinationController extends GetxController { Destination des = festuretoDestination(gfs); - print("=== gfs == ${des.toMap()}"); + //print("=== gfs == ${des.toMap()}"); double distanceToDest = double.infinity; var distance = const Distance(); distanceToDest = distance.as(LengthUnit.Meter, LatLng(currentLat, currentLon), LatLng(des.lat!, des.lon!)); - print("==== dist==${distanceToDest}"); + //print("==== dist==${distanceToDest}"); return distanceToDest; } @@ -744,7 +750,7 @@ class DestinationController extends GetxController { if (distanceToDest <= 500) { return 500; } - print("==== forced dist ==${distanceToDest}"); + //print("==== forced dist ==${distanceToDest}"); return _retValue; } diff --git a/lib/pages/gps/gps_page.dart b/lib/pages/gps/gps_page.dart index ee7dc39..61fa37d 100644 --- a/lib/pages/gps/gps_page.dart +++ b/lib/pages/gps/gps_page.dart @@ -38,7 +38,7 @@ class _GpsPageState extends State { var data = await db.getGPSData(team_name, event_code); gpsData.value = data; - print("--- gps data ${data} ----"); + //print("--- gps data ${data} ----"); } Widget getMarkerShape(GpsData i) { diff --git a/lib/pages/index/index_controller.dart b/lib/pages/index/index_controller.dart index 979e0da..c02e48d 100644 --- a/lib/pages/index/index_controller.dart +++ b/lib/pages/index/index_controller.dart @@ -268,7 +268,7 @@ class IndexController extends GetxController { } else { rogMode.value = 1; } - print('--- c rog mode --- ${rogMode.value}'); + //print('--- c rog mode --- ${rogMode.value}'); Get.toNamed(AppPages.INDEX); } diff --git a/lib/services/external_service.dart b/lib/services/external_service.dart index 20e8524..7eba1a7 100644 --- a/lib/services/external_service.dart +++ b/lib/services/external_service.dart @@ -344,13 +344,15 @@ class ExternalService { String timestampToTimeString(int timestamp) { // Convert timestamp to DateTime and format it as needed - var dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); + var dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp); + //print("^^^^ time ${dateTime}"); // Format dateTime to a time string (e.g., '12:00:00') // Adjust the format as needed return "${dateTime.hour}:${dateTime.minute}:${dateTime.second}"; } Future pushGPS() async { + //print("^^^^ pushed ^^^"); final IndexController indexController = Get.find(); //int userId = indexController.currentUser[0]["user"]["id"]; @@ -383,7 +385,7 @@ class ExternalService { }).toList(), }; - print("calling push gps step 2 ${payload}"); + //print("calling push gps step 2 ${payload}"); String urlS = 'https://rogaining.sumasen.net/gifuroge/get_waypoint_datas_from_rogapp'; @@ -395,15 +397,15 @@ class ExternalService { body: json.encode(payload), ); - print("GPS Data res ${response.statusCode}"); + //print("GPS Data res ${response.statusCode}"); if (response.statusCode == 200) { // Handle success // make local data as synced await GpsDatabaseHelper.instance.setSyncData(gpsDataList); - print("GPS Data sent successfully"); + //print("GPS Data sent successfully"); } else { // Handle error - print("Failed to send data"); + //print("Failed to send data"); } } return Future.value(false); diff --git a/lib/services/location_service.dart b/lib/services/location_service.dart index d3dcf81..2ef4713 100644 --- a/lib/services/location_service.dart +++ b/lib/services/location_service.dart @@ -174,7 +174,7 @@ class LocationService { '$serverUrl/api/inbound?ln1=$lon1&la1=$lat1&ln2=$lon2&la2=$lat2&ln3=$lon3&la3=$lat3&ln4=$lon4&la4=$lat4'; } } - print('++++++++$url'); + //print('++++++++$url'); final response = await http.get( Uri.parse(url), headers: { diff --git a/lib/utils/database_gps.dart b/lib/utils/database_gps.dart index d19e059..a60daa6 100644 --- a/lib/utils/database_gps.dart +++ b/lib/utils/database_gps.dart @@ -50,7 +50,7 @@ class GpsDatabaseHelper { nextOrder = nextOrder ?? 0; nextOrder = nextOrder + 1; gps.id = nextOrder; - print("---- insering ${gps.toMap()}"); + //print("---- insering ${gps.toMap()}"); int res = await db.insert( 'gps', gps.toMap(), @@ -68,7 +68,7 @@ class GpsDatabaseHelper { orderBy: 'created_at'); List gpsDatas = gpss.isNotEmpty ? gpss.map((e) => GpsData.fromMap(e)).toList() : []; - print("--------- db list $gpsDatas"); + //print("--------- db list $gpsDatas"); return gpsDatas; } diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index dbfba71..b405bbe 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -65,7 +65,7 @@ class BottomSheetNew extends GetView { } } else { GeoJsonFeature gf = indexController.currentFeature[0]; - print("=== photo sss ${gf.properties!["photos"]}"); + //print("=== photo sss ${gf.properties!["photos"]}"); if (gf.properties!["photos"] == null || gf.properties!["photos"] == "") { return const Image(image: AssetImage('assets/images/empty_image.png')); } else {