fixed gps page

This commit is contained in:
2023-11-22 23:06:38 +05:30
parent 4e4cfda40b
commit 23fde37e3d
6 changed files with 114 additions and 47 deletions

View File

@ -4,6 +4,7 @@ class GpsData {
String event_code; String event_code;
double lat; double lat;
double lon; double lon;
int is_checkin;
int created_at; int created_at;
GpsData( GpsData(
@ -12,7 +13,8 @@ class GpsData {
required this.event_code, required this.event_code,
required this.lat, required this.lat,
required this.lon, required this.lon,
required this.created_at}); required this.created_at,
this.is_checkin = 0});
factory GpsData.fromMap(Map<String, dynamic> json) { factory GpsData.fromMap(Map<String, dynamic> json) {
return GpsData( return GpsData(
@ -21,6 +23,7 @@ class GpsData {
event_code: json["event_code"], event_code: json["event_code"],
lat: json["lat"], lat: json["lat"],
lon: json["lon"], lon: json["lon"],
is_checkin: json["is_checkin"],
created_at: json["created_at"]); created_at: json["created_at"]);
} }
@ -31,6 +34,7 @@ class GpsData {
'event_code': event_code, 'event_code': event_code,
'lat': lat, 'lat': lat,
'lon': lon, 'lon': lon,
'is_checkin': is_checkin,
'created_at': created_at 'created_at': created_at
}; };
} }

View File

@ -499,6 +499,22 @@ class DestinationController extends GetxController {
} }
} }
Future<void> 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<void> checkForCheckin() async { Future<void> checkForCheckin() async {
print("--- Start of checkForCheckin function ---"); print("--- Start of checkForCheckin function ---");
@ -512,21 +528,22 @@ class DestinationController extends GetxController {
final la = position.latitude; final la = position.latitude;
final ln = position.longitude; final ln = position.longitude;
print("--- gps is ${la}, ${ln}"); //print("--- gps is ${la}, ${ln}");
//add gps to database //add gps to database
GpsDatabaseHelper db = GpsDatabaseHelper.instance; await addGPStoDB(la, ln);
final team_name = indexController.currentUser[0]["user"]['team_name']; // GpsDatabaseHelper db = GpsDatabaseHelper.instance;
final event_code = indexController.currentUser[0]["user"]["event_code"]; // final team_name = indexController.currentUser[0]["user"]['team_name'];
print("--- curr gps is ${la}, ${ln}"); // final event_code = indexController.currentUser[0]["user"]["event_code"];
GpsData gps_data = GpsData( // print("--- curr gps is ${la}, ${ln}");
id: 0, // GpsData gps_data = GpsData(
team_name: team_name, // id: 0,
event_code: event_code, // team_name: team_name,
lat: la, // event_code: event_code,
lon: ln, // lat: la,
created_at: DateTime.now().microsecondsSinceEpoch); // lon: ln,
await db.insertGps(gps_data); // created_at: DateTime.now().microsecondsSinceEpoch);
// await db.insertGps(gps_data);
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;
@ -648,6 +665,8 @@ class DestinationController extends GetxController {
DateTime now = DateTime.now(); DateTime now = DateTime.now();
String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(now); String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(now);
await addGPStoDB(destination.lat!, destination.lon!, isCheckin: 1);
// print("------ checkin event $eventCode ------"); // print("------ checkin event $eventCode ------");
ExternalService() ExternalService()
.makeCheckpoint(userId, token, formattedDate, team, cpNum.round(), .makeCheckpoint(userId, token, formattedDate, team, cpNum.round(),
@ -658,6 +677,10 @@ class DestinationController extends GetxController {
} }
} }
Future<void> removeCheckin(int cp) {
return ExternalService().removeCheckin(cp);
}
Future<void> startGame() async { Future<void> startGame() async {
//print("------ starting game ------"); //print("------ starting game ------");
await checkForCheckin(); await checkForCheckin();

View File

@ -35,8 +35,10 @@ class _GpsPageState extends State<GpsPage> {
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"];
GpsDatabaseHelper db = GpsDatabaseHelper.instance; GpsDatabaseHelper db = GpsDatabaseHelper.instance;
gpsData.value = await db.getGPSData(team_name, event_code); var data = await db.getGPSData(team_name, event_code);
print("--- gps data ${gpsData.value[gpsData.length - 1].lat} ----"); gpsData.value = data;
print("--- gps data ${data} ----");
} }
Widget getMarkerShape(GpsData i) { Widget getMarkerShape(GpsData i) {
@ -50,10 +52,11 @@ class _GpsPageState extends State<GpsPage> {
width: 22, width: 22,
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.circle,
color: Colors.purple.shade300, color: Colors.transparent,
border: Border.all( border: Border.all(
color: Colors.purple, color:
width: 3, i.is_checkin == 0 ? Colors.blueAccent : Colors.green,
width: i.is_checkin == 0 ? 0.4 : 2,
style: BorderStyle.solid)), style: BorderStyle.solid)),
child: const Stack( child: const Stack(
alignment: Alignment.center, alignment: Alignment.center,
@ -66,24 +69,26 @@ class _GpsPageState extends State<GpsPage> {
)), )),
), ),
Container( Container(
color: Colors.white, color: Colors.transparent,
child: Text( child: i.is_checkin == 1
DateTime.fromMicrosecondsSinceEpoch(i.created_at) ? Text(
.hour
.toString() +
":" +
DateTime.fromMicrosecondsSinceEpoch(i.created_at) DateTime.fromMicrosecondsSinceEpoch(i.created_at)
.minute .hour
.toString(), .toString() +
// ":" + ":" +
// DateTime.fromMicrosecondsSinceEpoch(i.created_at) DateTime.fromMicrosecondsSinceEpoch(i.created_at)
// .second .minute
// .toString(), .toString(),
style: const TextStyle( // ":" +
fontSize: 16, // DateTime.fromMicrosecondsSinceEpoch(i.created_at)
fontWeight: FontWeight.bold, // .second
color: Colors.black, // .toString(),
))), style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black,
))
: Container()),
], ],
); );
} }
@ -100,16 +105,7 @@ class _GpsPageState extends State<GpsPage> {
mapController: mapController, mapController: mapController,
options: MapOptions( options: MapOptions(
maxZoom: 18.4, maxZoom: 18.4,
onMapReady: () { onMapReady: () {},
subscription =
mapController!.mapEventStream.listen((MapEvent mapEvent) {
if (mapEvent is MapEventMoveStart) {
//print(DateTime.now().toString() + ' [MapEventMoveStart] START');
// do something
}
if (mapEvent is MapEventMoveEnd) {}
});
},
//center: LatLng(37.15319600454702, 139.58765950528198), //center: LatLng(37.15319600454702, 139.58765950528198),
bounds: indexController.currentBound.isNotEmpty bounds: indexController.currentBound.isNotEmpty
? indexController.currentBound[0] ? indexController.currentBound[0]

View File

@ -302,6 +302,44 @@ class ExternalService {
return res2; return res2;
} }
Future<bool> removeCheckin(int cp) async {
final IndexController indexController = Get.find<IndexController>();
//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: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'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<Map<String, dynamic>> usersEventCode( static Future<Map<String, dynamic>> usersEventCode(
String teamcode, String password) async { String teamcode, String password) async {
Map<String, dynamic> res = {}; Map<String, dynamic> res = {};

View File

@ -35,7 +35,8 @@ class GpsDatabaseHelper {
team_name TEXT, team_name TEXT,
event_code TEXT, event_code TEXT,
lat REAL, lat REAL,
lon REAL, lon REAL,
is_checkin int,
created_at INTEGER created_at INTEGER
) )
'''); ''');

View File

@ -521,6 +521,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
isAlreadyCheckedIn == true && destination.cp != -1 isAlreadyCheckedIn == true && destination.cp != -1
? ElevatedButton( ? ElevatedButton(
onPressed: () async { onPressed: () async {
await destinationController
.removeCheckin(destination.cp!.toInt());
destinationController destinationController
.deleteDestination(destination); .deleteDestination(destination);
Get.back(); Get.back();
@ -628,6 +630,9 @@ class BottomSheetNew extends GetView<BottomSheetController> {
.startRogaining() .startRogaining()
.then((value) => Get.back()); .then((value) => Get.back());
} else { } else {
if (destination.cp == -1) {
return;
}
Get.back(); Get.back();
await destinationController await destinationController
.callforCheckin(destination); .callforCheckin(destination);