From 23fde37e3d3bc6e197d9a31e40457daacc24f492 Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Wed, 22 Nov 2023 23:06:38 +0530 Subject: [PATCH] fixed gps page --- lib/model/gps_data.dart | 6 +- .../destination/destination_controller.dart | 49 +++++++++++---- lib/pages/gps/gps_page.dart | 60 +++++++++---------- lib/services/external_service.dart | 38 ++++++++++++ lib/utils/database_gps.dart | 3 +- lib/widgets/bottom_sheet_new.dart | 5 ++ 6 files changed, 114 insertions(+), 47 deletions(-) diff --git a/lib/model/gps_data.dart b/lib/model/gps_data.dart index f49431e..f6a3aa8 100644 --- a/lib/model/gps_data.dart +++ b/lib/model/gps_data.dart @@ -4,6 +4,7 @@ class GpsData { String event_code; double lat; double lon; + int is_checkin; int created_at; GpsData( @@ -12,7 +13,8 @@ class GpsData { required this.event_code, required this.lat, required this.lon, - required this.created_at}); + required this.created_at, + this.is_checkin = 0}); factory GpsData.fromMap(Map json) { return GpsData( @@ -21,6 +23,7 @@ class GpsData { event_code: json["event_code"], lat: json["lat"], lon: json["lon"], + is_checkin: json["is_checkin"], created_at: json["created_at"]); } @@ -31,6 +34,7 @@ class GpsData { 'event_code': event_code, 'lat': lat, 'lon': lon, + 'is_checkin': is_checkin, 'created_at': created_at }; } diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index 34e518d..b23ebc4 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -499,6 +499,22 @@ class DestinationController extends GetxController { } } + Future addGPStoDB(double la, double ln, {isCheckin = 0}) async { + GpsDatabaseHelper db = GpsDatabaseHelper.instance; + final team_name = indexController.currentUser[0]["user"]['team_name']; + final event_code = indexController.currentUser[0]["user"]["event_code"]; + GpsData gps_data = GpsData( + id: 0, + team_name: team_name, + event_code: event_code, + lat: la, + lon: ln, + is_checkin: isCheckin, + created_at: DateTime.now().microsecondsSinceEpoch); + var res = await db.insertGps(gps_data); + print("==gps res == ${res}"); + } + Future checkForCheckin() async { print("--- Start of checkForCheckin function ---"); @@ -512,21 +528,22 @@ class DestinationController extends GetxController { final la = position.latitude; final ln = position.longitude; - print("--- gps is ${la}, ${ln}"); + //print("--- gps is ${la}, ${ln}"); //add gps to database - GpsDatabaseHelper db = GpsDatabaseHelper.instance; - final team_name = indexController.currentUser[0]["user"]['team_name']; - final event_code = indexController.currentUser[0]["user"]["event_code"]; - print("--- curr gps is ${la}, ${ln}"); - GpsData gps_data = GpsData( - id: 0, - team_name: team_name, - event_code: event_code, - lat: la, - lon: ln, - created_at: DateTime.now().microsecondsSinceEpoch); - await db.insertGps(gps_data); + await addGPStoDB(la, ln); + // GpsDatabaseHelper db = GpsDatabaseHelper.instance; + // final team_name = indexController.currentUser[0]["user"]['team_name']; + // final event_code = indexController.currentUser[0]["user"]["event_code"]; + // print("--- curr gps is ${la}, ${ln}"); + // GpsData gps_data = GpsData( + // id: 0, + // team_name: team_name, + // event_code: event_code, + // lat: la, + // lon: ln, + // created_at: DateTime.now().microsecondsSinceEpoch); + // await db.insertGps(gps_data); for (GeoJsonFeature fs in indexController.locations[0].collection) { GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint; @@ -648,6 +665,8 @@ class DestinationController extends GetxController { DateTime now = DateTime.now(); String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(now); + await addGPStoDB(destination.lat!, destination.lon!, isCheckin: 1); + // print("------ checkin event $eventCode ------"); ExternalService() .makeCheckpoint(userId, token, formattedDate, team, cpNum.round(), @@ -658,6 +677,10 @@ class DestinationController extends GetxController { } } + Future removeCheckin(int cp) { + return ExternalService().removeCheckin(cp); + } + Future startGame() async { //print("------ starting game ------"); await checkForCheckin(); diff --git a/lib/pages/gps/gps_page.dart b/lib/pages/gps/gps_page.dart index fde9076..ee7dc39 100644 --- a/lib/pages/gps/gps_page.dart +++ b/lib/pages/gps/gps_page.dart @@ -35,8 +35,10 @@ class _GpsPageState extends State { final team_name = indexController.currentUser[0]["user"]['team_name']; final event_code = indexController.currentUser[0]["user"]["event_code"]; GpsDatabaseHelper db = GpsDatabaseHelper.instance; - gpsData.value = await db.getGPSData(team_name, event_code); - print("--- gps data ${gpsData.value[gpsData.length - 1].lat} ----"); + var data = await db.getGPSData(team_name, event_code); + gpsData.value = data; + + print("--- gps data ${data} ----"); } Widget getMarkerShape(GpsData i) { @@ -50,10 +52,11 @@ class _GpsPageState extends State { width: 22, decoration: BoxDecoration( shape: BoxShape.circle, - color: Colors.purple.shade300, + color: Colors.transparent, border: Border.all( - color: Colors.purple, - width: 3, + color: + i.is_checkin == 0 ? Colors.blueAccent : Colors.green, + width: i.is_checkin == 0 ? 0.4 : 2, style: BorderStyle.solid)), child: const Stack( alignment: Alignment.center, @@ -66,24 +69,26 @@ class _GpsPageState extends State { )), ), Container( - color: Colors.white, - child: Text( - DateTime.fromMicrosecondsSinceEpoch(i.created_at) - .hour - .toString() + - ":" + + color: Colors.transparent, + child: i.is_checkin == 1 + ? Text( DateTime.fromMicrosecondsSinceEpoch(i.created_at) - .minute - .toString(), - // ":" + - // DateTime.fromMicrosecondsSinceEpoch(i.created_at) - // .second - // .toString(), - style: const TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - color: Colors.black, - ))), + .hour + .toString() + + ":" + + DateTime.fromMicrosecondsSinceEpoch(i.created_at) + .minute + .toString(), + // ":" + + // DateTime.fromMicrosecondsSinceEpoch(i.created_at) + // .second + // .toString(), + style: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + color: Colors.black, + )) + : Container()), ], ); } @@ -100,16 +105,7 @@ class _GpsPageState extends State { mapController: mapController, options: MapOptions( maxZoom: 18.4, - onMapReady: () { - subscription = - mapController!.mapEventStream.listen((MapEvent mapEvent) { - if (mapEvent is MapEventMoveStart) { - //print(DateTime.now().toString() + ' [MapEventMoveStart] START'); - // do something - } - if (mapEvent is MapEventMoveEnd) {} - }); - }, + onMapReady: () {}, //center: LatLng(37.15319600454702, 139.58765950528198), bounds: indexController.currentBound.isNotEmpty ? indexController.currentBound[0] diff --git a/lib/services/external_service.dart b/lib/services/external_service.dart index 009c3b0..9e80516 100644 --- a/lib/services/external_service.dart +++ b/lib/services/external_service.dart @@ -302,6 +302,44 @@ class ExternalService { return res2; } + Future removeCheckin(int cp) async { + final IndexController indexController = Get.find(); + + //int userId = indexController.currentUser[0]["user"]["id"]; + //print("--- Pressed -----"); + String team = indexController.currentUser[0]["user"]['team_name']; + //print("--- _team : ${_team}-----"); + String eventCode = indexController.currentUser[0]["user"]["event_code"]; + + if (indexController.connectionStatusName.value != "wifi" && + indexController.connectionStatusName.value != "mobile") { + return Future.value(false); + } else { + String url = + 'https://rogaining.sumasen.net/gifuroge/remove_checkin_from_rogapp'; + //print('++++++++$url'); + final http.Response response = await http.post( + Uri.parse(url), + headers: { + 'Content-Type': 'application/json; charset=UTF-8', + }, + body: jsonEncode({ + 'event_code': eventCode, + 'team_name': team, + 'cp_number': cp.toString() + }), + ); + + //print("---- remove checkin ---- ${response.statusCode}"); + + if (response.statusCode == 200) { + return Future.value(true); + //print('----_res : $res ----'); + } + } + return Future.value(false); + } + static Future> usersEventCode( String teamcode, String password) async { Map res = {}; diff --git a/lib/utils/database_gps.dart b/lib/utils/database_gps.dart index a0c4c81..96a922a 100644 --- a/lib/utils/database_gps.dart +++ b/lib/utils/database_gps.dart @@ -35,7 +35,8 @@ class GpsDatabaseHelper { team_name TEXT, event_code TEXT, lat REAL, - lon REAL, + lon REAL, + is_checkin int, created_at INTEGER ) '''); diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index 46b0f66..091dfa4 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -521,6 +521,8 @@ class BottomSheetNew extends GetView { isAlreadyCheckedIn == true && destination.cp != -1 ? ElevatedButton( onPressed: () async { + await destinationController + .removeCheckin(destination.cp!.toInt()); destinationController .deleteDestination(destination); Get.back(); @@ -628,6 +630,9 @@ class BottomSheetNew extends GetView { .startRogaining() .then((value) => Get.back()); } else { + if (destination.cp == -1) { + return; + } Get.back(); await destinationController .callforCheckin(destination);