fixed gps page
This commit is contained in:
@ -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<String, dynamic> 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
|
||||
};
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
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<void> removeCheckin(int cp) {
|
||||
return ExternalService().removeCheckin(cp);
|
||||
}
|
||||
|
||||
Future<void> startGame() async {
|
||||
//print("------ starting game ------");
|
||||
await checkForCheckin();
|
||||
|
||||
@ -35,8 +35,10 @@ class _GpsPageState extends State<GpsPage> {
|
||||
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<GpsPage> {
|
||||
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<GpsPage> {
|
||||
)),
|
||||
),
|
||||
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<GpsPage> {
|
||||
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]
|
||||
|
||||
@ -302,6 +302,44 @@ class ExternalService {
|
||||
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(
|
||||
String teamcode, String password) async {
|
||||
Map<String, dynamic> res = {};
|
||||
|
||||
@ -35,7 +35,8 @@ class GpsDatabaseHelper {
|
||||
team_name TEXT,
|
||||
event_code TEXT,
|
||||
lat REAL,
|
||||
lon REAL,
|
||||
lon REAL,
|
||||
is_checkin int,
|
||||
created_at INTEGER
|
||||
)
|
||||
''');
|
||||
|
||||
@ -521,6 +521,8 @@ class BottomSheetNew extends GetView<BottomSheetController> {
|
||||
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<BottomSheetController> {
|
||||
.startRogaining()
|
||||
.then((value) => Get.back());
|
||||
} else {
|
||||
if (destination.cp == -1) {
|
||||
return;
|
||||
}
|
||||
Get.back();
|
||||
await destinationController
|
||||
.callforCheckin(destination);
|
||||
|
||||
Reference in New Issue
Block a user