added buypoint images

This commit is contained in:
Mohamed Nouffer
2023-09-14 00:08:53 +05:30
parent 30fea7cf8a
commit aa7b13b76a
5 changed files with 348 additions and 235 deletions

View File

@ -85,7 +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(); //destinationController.startGame();
} }
break; break;
case AppLifecycleState.inactive: case AppLifecycleState.inactive:

View File

@ -24,6 +24,7 @@ class Destination {
double? buy_point; double? buy_point;
int? hidden_location; int? hidden_location;
String? checkin_image; String? checkin_image;
String? buypoint_image;
Destination({ Destination({
this.name, this.name,
@ -48,7 +49,8 @@ class Destination {
this.checkin_point, this.checkin_point,
this.buy_point, this.buy_point,
this.hidden_location, this.hidden_location,
this.checkin_image this.checkin_image,
this.buypoint_image
}); });
factory Destination.fromMap(Map<String, dynamic> json) { factory Destination.fromMap(Map<String, dynamic> json) {
@ -79,7 +81,8 @@ class Destination {
checkin_point: json['checkin_point'], checkin_point: json['checkin_point'],
buy_point: json['buy_point'], buy_point: json['buy_point'],
hidden_location: json['hidden_location'], hidden_location: json['hidden_location'],
checkin_image: json['checkin_image'] checkin_image: json['checkin_image'],
buypoint_image: json["buypoint_image"]
); );
} }
@ -109,7 +112,8 @@ class Destination {
'checkin_point' : checkin_point, 'checkin_point' : checkin_point,
'buy_point' : buy_point, 'buy_point' : buy_point,
'hidden_location' : hidden_location, 'hidden_location' : hidden_location,
'checkin_image': checkin_image 'checkin_image': checkin_image,
'buypoint_image' : buypoint_image
}; };
} }

View File

@ -8,118 +8,160 @@ import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/index/index_controller.dart'; import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/services/external_service.dart'; import 'package:rogapp/services/external_service.dart';
class CameraPage extends StatelessWidget { class CameraPage extends StatelessWidget {
Destination? destination; Destination? destination;
CameraPage({Key? key, this.destination}) : super(key: key); Destination? dbDest;
DestinationController destinationController = Get.find<DestinationController>(); CameraPage({Key? key, this.destination, this.dbDest}) : super(key: key);
DestinationController destinationController =
Get.find<DestinationController>();
IndexController indexController = Get.find<IndexController>(); IndexController indexController = Get.find<IndexController>();
var settingGoal = false.obs; var settingGoal = false.obs;
Timer? timer; Timer? timer;
ImageProvider getFinishImage(){ ImageProvider getFinishImage() {
if(destinationController.photos.isNotEmpty){ if (destinationController.photos.isNotEmpty) {
return FileImage(destinationController.photos[0]); return FileImage(destinationController.photos[0]);
} } else {
else{
return const AssetImage('assets/images/empty_image.png'); return const AssetImage('assets/images/empty_image.png');
} }
} }
Widget getAction(BuildContext context) { Widget getAction(BuildContext context) {
if(destinationController.is_at_goal.value && destinationController.is_in_rog.value){
print("----cccheckin is --- ${dbDest?.checkedin} ----");
if (destinationController.is_at_goal.value &&
destinationController.is_in_rog.value) {
return Row( return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [ children: [
ElevatedButton( ElevatedButton(
onPressed: (){ onPressed: () {
if(settingGoal.value ==false){ if (settingGoal.value == false) {
destinationController.openCamera(context); destinationController.openCamera(context);
} }
}, },
child: Text("take_photo of the clock".tr) child: Text("take_photo of the clock".tr)),
), Obx(() => destinationController.photos.isNotEmpty
Obx(() => ? settingGoal.value == false
destinationController.photos.isNotEmpty ? ? ElevatedButton(
settingGoal.value == false ? style:
ElevatedButton( ElevatedButton.styleFrom(backgroundColor: Colors.red),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.red
),
onPressed: () async { onPressed: () async {
print(
print("----- user isss ${indexController.currentUser[0]} -----"); "----- 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"];
//print("--- Pressed -----"); //print("--- Pressed -----");
String _team = indexController.currentUser[0]["user"]['team_name']; String _team = indexController.currentUser[0]["user"]
['team_name'];
//print("--- _team : ${_team}-----"); //print("--- _team : ${_team}-----");
String _event_code = indexController.currentUser[0]["user"]["event_code"]; String _event_code = indexController.currentUser[0]
["user"]["event_code"];
//print("--- _event_code : ${_event_code}-----"); //print("--- _event_code : ${_event_code}-----");
String _token = indexController.currentUser[0]["token"]; String _token =
indexController.currentUser[0]["token"];
//print("--- _token : ${_token}-----"); //print("--- _token : ${_token}-----");
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 ExternalService().makeGoal(userId, _token, _team, destinationController.photos[0].path, formattedDate, _event_code).then((value){ await ExternalService()
print("---called ext api ${value['status']} ------"); .makeGoal(
if(value['status'] == 'OK'){ userId,
_token,
_team,
destinationController.photos[0].path,
formattedDate,
_event_code)
.then((value) {
print(
"---called ext api ${value['status']} ------");
if (value['status'] == 'OK') {
Get.back(); Get.back();
destinationController.skip_gps = false; destinationController.skip_gps = false;
Get.snackbar("目標が保存されました", "目標が正常に追加されました"); Get.snackbar("目標が保存されました", "目標が正常に追加されました");
destinationController.resetRogaining(); destinationController.resetRogaining();
} } else {
else{
print("---- status ${value['status']} ---- "); print("---- status ${value['status']} ---- ");
Get.snackbar("目標が追加されていません", "please_try_again"); Get.snackbar("目標が追加されていません", "please_try_again");
} }
}); });
} } on Exception catch (_) {
on Exception catch(_){
settingGoal.value = false; settingGoal.value = false;
} } finally {
finally{
settingGoal.value = false; settingGoal.value = false;
} }
}, },
child:Text("finish_goal".tr) child: Text("finish_goal".tr))
) : Container(
:
Container(
child: const Center( child: const Center(
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
), ),
) )
: : Container())
Container()
)
], ],
); );
} } else if (destinationController.is_in_rog.value &&
else{ dbDest?.checkedin != null &&
dbDest?.checkedin == true) {
//make buypoint image
return Row( return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [ children: [
Obx(() => Obx(() => ElevatedButton(
ElevatedButton( onPressed: () {
onPressed: (){
destinationController.openCamera(context); destinationController.openCamera(context);
}, },
child: destinationController.photos.isNotEmpty ? const Text("再撮影") : const Text("撮影") child: destinationController.photos.isNotEmpty
) ? const Text("再撮影")
), : const Text("撮影"))),
Obx(() => Obx(() => destinationController.photos.isNotEmpty
destinationController.photos.isNotEmpty ? ? ElevatedButton(
ElevatedButton( style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
style: ElevatedButton.styleFrom( onPressed: () async {
backgroundColor: Colors.red print(
), "##### current destination ${indexController.currentDestinationFeature[0].sub_loc_id} #######");
onPressed: (){ await destinationController.makeBuyPoint(
print("##### current destination ${indexController.currentDestinationFeature[0].sub_loc_id} #######"); destination!,
destinationController.makeCheckin(indexController.currentDestinationFeature[0], true, destinationController.photos[0].path); destinationController.photos[0].path);
Get.back();
destinationController.rogaining_counted.value = true;
destinationController.skip_gps = false;
destinationController.is_photo_shoot.value = false;
Get.snackbar("追加した", "領収書の写真を追加しました");
},
child: const Text("レシートの写真を撮る"))
: Container())
],
);
} else {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Obx(() => ElevatedButton(
onPressed: () {
destinationController.openCamera(context);
},
child: destinationController.photos.isNotEmpty
? const Text("再撮影")
: const Text("撮影"))),
Obx(() => destinationController.photos.isNotEmpty
? ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: () async {
print(
"##### current destination ${indexController.currentDestinationFeature[0].sub_loc_id} #######");
await destinationController.makeCheckin(
indexController.currentDestinationFeature[0],
true,
destinationController.photos[0].path);
Get.back(); Get.back();
destinationController.rogaining_counted.value = true; destinationController.rogaining_counted.value = true;
destinationController.skip_gps = false; destinationController.skip_gps = false;
@ -139,10 +181,8 @@ class CameraPage extends StatelessWidget {
// } // }
// }); // });
}, },
child: const Text("チェックイン") child: const Text("チェックイン"))
): : Container())
Container()
)
], ],
); );
} }
@ -154,30 +194,28 @@ class CameraPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if(destinationController.is_in_rog.value){ if (destinationController.is_in_rog.value) {
return Scaffold( return Scaffold(
appBar: appBar: destinationController.is_in_rog.value &&
destinationController.is_in_rog.value && destinationController.rogaining_counted.value == true ? destinationController.rogaining_counted.value == true
AppBar( ? AppBar(
title: destination!.cp == -1 ? title: destination!.cp == -1
Text("finishing_rogaining".tr) ? Text("finishing_rogaining".tr)
: : Text("cp_pls_take_photo".tr),
Text("cp_pls_take_photo".tr)
,
leading: IconButton( leading: IconButton(
icon: Text("cancel".tr), icon: Text("cancel".tr),
onPressed: (){ onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
destinationController.skip_10s = true; destinationController.skip_10s = true;
timer = Timer.periodic(const Duration(seconds: 10), (Timer t){ timer =
Timer.periodic(const Duration(seconds: 10), (Timer t) {
destinationController.skip_10s = false; destinationController.skip_10s = false;
}); });
}, },
), ),
centerTitle: true, centerTitle: true,
) )
: : AppBar(
AppBar(
title: const Text("チェックポイント"), title: const Text("チェックポイント"),
), ),
body: Column( body: Column(
@ -186,17 +224,13 @@ class CameraPage extends StatelessWidget {
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Center( child: Center(
child: Obx(() => child: Obx(
Container( () => Container(
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
height: 370, height: 370,
decoration: BoxDecoration( decoration: BoxDecoration(
image: image: DecorationImage(
DecorationImage( image: getFinishImage(), fit: BoxFit.cover)),
image: getFinishImage(),
fit: BoxFit.cover
)
),
), ),
), ),
), ),
@ -205,34 +239,38 @@ class CameraPage extends StatelessWidget {
], ],
), ),
); );
} } else {
else {
return StartRogaining(); return StartRogaining();
} }
} }
} }
class StartRogaining extends StatelessWidget { class StartRogaining extends StatelessWidget {
StartRogaining({Key? key}) : super(key: key); StartRogaining({Key? key}) : super(key: key);
DestinationController destinationController = Get.find<DestinationController>(); DestinationController destinationController =
Get.find<DestinationController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text("Not started yet".tr,), title: Text(
"Not started yet".tr,
),
), ),
body: Container( body: Container(
child: Center( child: Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text("You have not started rogaining yet.".tr, style: const TextStyle(fontSize: 24)), Text("You have not started rogaining yet.".tr,
const SizedBox(height: 40.0,), style: const TextStyle(fontSize: 24)),
const SizedBox(
height: 40.0,
),
ElevatedButton( ElevatedButton(
onPressed: (){ onPressed: () {
Get.back(); Get.back();
destinationController.skip_gps = false; destinationController.skip_gps = false;
}, },
@ -249,23 +287,29 @@ class StartRogaining extends StatelessWidget {
class NotAtGoal extends StatelessWidget { class NotAtGoal extends StatelessWidget {
NotAtGoal({Key? key}) : super(key: key); NotAtGoal({Key? key}) : super(key: key);
DestinationController destinationController = Get.find<DestinationController>(); DestinationController destinationController =
Get.find<DestinationController>();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text("Not reached the goal yet".tr,), title: Text(
"Not reached the goal yet".tr,
),
), ),
body: Container( body: Container(
child: Center( child: Center(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text("You have not reached the goal yet.".tr, style: const TextStyle(fontSize: 24)), Text("You have not reached the goal yet.".tr,
const SizedBox(height: 40.0,), style: const TextStyle(fontSize: 24)),
const SizedBox(
height: 40.0,
),
ElevatedButton( ElevatedButton(
onPressed: (){ onPressed: () {
Get.back(); Get.back();
destinationController.skip_gps = false; destinationController.skip_gps = false;
}, },

View File

@ -108,7 +108,7 @@ class DestinationController extends GetxController {
hidden_location: fs.properties!["hidden_location"] == true ? 1 : 0); hidden_location: fs.properties!["hidden_location"] == true ? 1 : 0);
} }
void startTimerLocation(GeoJsonFeature fs, double distance) { Future<void> startTimerLocation(GeoJsonFeature fs, double distance) async {
print("---- in startTimer ----"); print("---- in startTimer ----");
print("---- is in rog is ${is_in_rog} ----"); print("---- is in rog is ${is_in_rog} ----");
//skip_gps = true; //skip_gps = true;
@ -125,21 +125,27 @@ class DestinationController extends GetxController {
// } // }
indexController.currentFeature.add(fs); indexController.currentFeature.add(fs);
print("---- before calling startTimer ----"); print("---- before calling startTimer ----");
startTimer(d, distance); await startTimer(d, distance);
return; return;
} }
} }
void startTimer(Destination d, double distance) async { Future<void> startTimer(Destination d, double distance) async {
print("=== passed dest is ${d.location_id} ${d.checkedin} ===="); print("=== passed dest is ${d.location_id} ${d.checkedin} ====");
skip_gps = true; //skip_gps = true;
print("---- in startTimer ----"); print("---- in startTimer ----");
DatabaseHelper db = DatabaseHelper.instance; DatabaseHelper db = DatabaseHelper.instance;
List<Destination> ds = await db.getDestinationByLatLon(d.lat!, d.lon!); List<Destination> ds = await db.getDestinationByLatLon(d.lat!, d.lon!);
Destination? dss;
if(ds.isNotEmpty){
dss = ds.first;
}
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 buyPoint = dss != null && dss.buy_point != null && dss.buy_point! > 0 ? true : false;
bool buyPointImageAdded = dss != null && dss.buypoint_image != null ? true : false;
bool locationAlreadyCheckedIn = bool locationAlreadyCheckedIn =
ds.length > 0 && ds[0].checkedin == true ? true : false; ds.length > 0 && ds[0].checkedin == true ? true : false;
bool isuserLoggedIn = indexController.currentUser.isNotEmpty ? true : false; bool isuserLoggedIn = indexController.currentUser.isNotEmpty ? true : false;
@ -160,7 +166,7 @@ class DestinationController extends GetxController {
if (is_photo_shoot.value == true) { if (is_photo_shoot.value == true) {
photos.clear(); photos.clear();
showModalBottomSheet( await showModalBottomSheet(
constraints: BoxConstraints.loose(Size(Get.width, Get.height * 0.75)), constraints: BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
context: Get.context!, context: Get.context!,
isScrollControlled: true, isScrollControlled: true,
@ -181,7 +187,7 @@ class DestinationController extends GetxController {
chekcs = 1; chekcs = 1;
is_in_checkin.value = true; is_in_checkin.value = true;
is_at_start.value = true; is_at_start.value = true;
showModalBottomSheet( await showModalBottomSheet(
constraints: constraints:
BoxConstraints.loose(Size(Get.width, Get.height * 0.75)), BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
context: Get.context!, context: Get.context!,
@ -192,11 +198,12 @@ class DestinationController extends GetxController {
is_at_start.value = false; is_at_start.value = false;
is_in_checkin.value = false; is_in_checkin.value = false;
}); });
return;
} else if (is_in_rog.value == true && indexController.rog_mode == 1) { } else if (is_in_rog.value == true && indexController.rog_mode == 1) {
print("----- in location popup checkin cp - ${d.cp}----"); print("----- in location popup checkin cp - ${d.cp}----");
chekcs = 2; chekcs = 2;
is_in_checkin.value = true; is_in_checkin.value = true;
showModalBottomSheet( await showModalBottomSheet(
constraints: constraints:
BoxConstraints.loose(Size(Get.width, Get.height * 0.75)), BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
context: Get.context!, context: Get.context!,
@ -206,6 +213,7 @@ class DestinationController extends GetxController {
chekcs = 0; chekcs = 0;
is_in_checkin.value = false; is_in_checkin.value = false;
}); });
return;
} }
} }
@ -224,6 +232,7 @@ class DestinationController extends GetxController {
} }
skip_gps = false; skip_gps = false;
} }
return;
} else { } else {
print("--- hidden loc ${d.hidden_location} ----"); print("--- hidden loc ${d.hidden_location} ----");
// ask for checkin // ask for checkin
@ -234,7 +243,8 @@ class DestinationController extends GetxController {
chekcs = 3; chekcs = 3;
is_in_checkin.value = true; is_in_checkin.value = true;
photos.clear(); photos.clear();
showModalBottomSheet( print("--- calling checkin ---");
await showModalBottomSheet(
constraints: constraints:
BoxConstraints.loose(Size(Get.width, Get.height * 0.75)), BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
context: Get.context!, context: Get.context!,
@ -247,10 +257,11 @@ class DestinationController extends GetxController {
chekcs = 0; chekcs = 0;
is_in_checkin.value = false; is_in_checkin.value = false;
}); });
return;
} else if (is_in_rog.value == true && d.cp != -1) { } else if (is_in_rog.value == true && d.cp != -1) {
chekcs = 4; chekcs = 4;
is_in_checkin.value = true; is_in_checkin.value = true;
showMaterialModalBottomSheet( await showMaterialModalBottomSheet(
expand: true, expand: true,
context: Get.context!, context: Get.context!,
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
@ -259,6 +270,7 @@ class DestinationController extends GetxController {
chekcs = 0; chekcs = 0;
is_in_checkin.value = false; is_in_checkin.value = false;
}); });
return;
// showModalBottomSheet(context: Get.context!, isScrollControlled: true, // showModalBottomSheet(context: Get.context!, isScrollControlled: true,
// builder:((context) => BottomSheetNew()) // builder:((context) => BottomSheetNew())
// ).whenComplete((){ // ).whenComplete((){
@ -268,6 +280,31 @@ class DestinationController extends GetxController {
// }); // });
} }
} }
} else if (checkinRadious >= distance &&
locationAlreadyCheckedIn == true &&
buyPointImageAdded == false &&
ds.isNotEmpty &&
buyPoint == true &&
is_in_rog.value == true) {
chekcs = 5;
is_in_checkin.value = true;
photos.clear();
print(
"--- open buy point ${buyPointImageAdded} ${d.buypoint_image} ----");
await showModalBottomSheet(
constraints: BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
context: Get.context!,
isScrollControlled: true,
builder: ((context) => CameraPage(
destination: d,
dbDest: ds.first,
))).whenComplete(() {
skip_gps = false;
rogaining_counted.value = true;
chekcs = 0;
is_in_checkin.value = false;
});
return;
} }
print("---- cp --- ${d.cp} -----"); print("---- cp --- ${d.cp} -----");
print("--- at goal $is_at_goal ---"); print("--- at goal $is_at_goal ---");
@ -286,7 +323,7 @@ class DestinationController extends GetxController {
chekcs = 5; chekcs = 5;
is_at_goal.value = true; is_at_goal.value = true;
photos.clear(); photos.clear();
showModalBottomSheet( await showModalBottomSheet(
constraints: constraints:
BoxConstraints.loose(Size(Get.width, Get.height * 0.75)), BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
context: Get.context!, context: Get.context!,
@ -298,6 +335,7 @@ class DestinationController extends GetxController {
chekcs = 0; chekcs = 0;
is_at_goal.value = false; is_at_goal.value = false;
}); });
return;
} else if (is_in_rog.value == false && } else if (is_in_rog.value == false &&
indexController.rog_mode == 1 && indexController.rog_mode == 1 &&
DateTime.now().difference(last_goal_at).inHours >= 24) { DateTime.now().difference(last_goal_at).inHours >= 24) {
@ -305,7 +343,7 @@ class DestinationController extends GetxController {
print("---- in start -----"); print("---- in start -----");
chekcs = 6; chekcs = 6;
is_at_start.value = true; is_at_start.value = true;
showModalBottomSheet( await showModalBottomSheet(
constraints: constraints:
BoxConstraints.loose(Size(Get.width, Get.height * 0.75)), BoxConstraints.loose(Size(Get.width, Get.height * 0.75)),
context: Get.context!, context: Get.context!,
@ -316,6 +354,7 @@ class DestinationController extends GetxController {
chekcs = 0; chekcs = 0;
is_at_start.value = false; is_at_start.value = false;
}); });
return;
} }
} }
print("==== _chekcs $chekcs ===="); print("==== _chekcs $chekcs ====");
@ -358,7 +397,7 @@ class DestinationController extends GetxController {
db.deleteAllDestinations().then((value) { db.deleteAllDestinations().then((value) {
PopulateDestinations(); PopulateDestinations();
startGPSTimer(); startGPSTimer();
startGame(); //startGame();
//initGPS(); //initGPS();
}); });
} }
@ -440,12 +479,12 @@ class DestinationController extends GetxController {
} }
} }
void checkForCheckin() async { Future<void> checkForCheckin() async {
print("--- Start of checkForCheckin function ---"); print("--- Start of checkForCheckin function ---");
try { try {
print("--- 000 ---- $skip_gps----"); print("--- 000 ---- $skip_gps----");
await Future.delayed(const Duration(milliseconds: 3500)); await Future.delayed(const Duration(milliseconds: 2500));
final la = current_lat; final la = current_lat;
final ln = current_lon; final ln = current_lon;
for (GeoJsonFeature fs in indexController.locations[0].collection) { for (GeoJsonFeature fs in indexController.locations[0].collection) {
@ -458,20 +497,23 @@ class DestinationController extends GetxController {
var distanceFs = const Distance(); var distanceFs = const Distance();
double distFs = distanceFs.as( double distFs = distanceFs.as(
LengthUnit.Meter, LatLng(latFs, lonFs), LatLng(la, ln)); LengthUnit.Meter, LatLng(latFs, lonFs), LatLng(la, ln));
Destination des = festuretoDestination(fs);
if (distFs <= 250 && skip_gps == false) { if (distFs <= des.checkin_radious! && skip_gps == false) {
print("--- 789 ---- $skip_gps----"); print("--- 789 ---- $skip_gps----");
//near a location //near a location
print("---- before call startTimerLocation ----"); print("---- before call startTimerLocation ----");
startTimerLocation(fs, distFs); await startTimerLocation(fs, distFs);
return;
} }
} }
print("--- 123 ---- $skip_gps----"); print("--- 123 ---- $skip_gps----");
} catch (e) { } catch (e) {
print("An error occurred: $e"); print("An error occurred: $e");
await checkForCheckin();
} finally { } finally {
print("--- End of checkForCheckin function, calling recursively ---"); print("--- End of checkForCheckin function, calling recursively ---");
checkForCheckin(); await checkForCheckin();
} }
} }
@ -534,7 +576,15 @@ class DestinationController extends GetxController {
saveGameState(); saveGameState();
} }
void makeCheckin( Future<void> makeBuyPoint(Destination destination, String imageurl) async {
DatabaseHelper db = DatabaseHelper.instance;
await db.updateBuyPoint(destination, imageurl);
PopulateDestinations();
await GallerySaver.saveImage(imageurl);
}
Future<void> makeCheckin(
Destination destination, bool action, String imageurl) async { Destination destination, bool action, String imageurl) async {
print( print(
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${destination.sub_loc_id}@@@@@@@@@@@"); "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${destination.sub_loc_id}@@@@@@@@@@@");
@ -550,7 +600,7 @@ class DestinationController extends GetxController {
await GallerySaver.saveImage(imageurl); await GallerySaver.saveImage(imageurl);
//PopulateDestinations(); PopulateDestinations();
/// post to NATNAT /// post to NATNAT
if (indexController.currentUser.isNotEmpty) { if (indexController.currentUser.isNotEmpty) {
@ -656,7 +706,7 @@ class DestinationController extends GetxController {
_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: 1), (timer) async {
Position position = await Geolocator.getCurrentPosition( Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high); desiredAccuracy: LocationAccuracy.high);
current_lat = position.latitude; current_lat = position.latitude;
@ -677,8 +727,8 @@ class DestinationController extends GetxController {
_GPStimer?.cancel(); _GPStimer?.cancel();
} }
void startGame() { Future<void> startGame() async {
checkForCheckin(); await checkForCheckin();
} }
@override @override

View File

@ -49,7 +49,8 @@ class DatabaseHelper{
checkin_point REAL, checkin_point REAL,
buy_point REAL, buy_point REAL,
hidden_location INTEGER, hidden_location INTEGER,
checkin_image TEXT checkin_image TEXT,
buypoint_image TEXT
) )
'''); ''');
@ -259,6 +260,20 @@ class DatabaseHelper{
return res; return res;
} }
Future<int> updateBuyPoint(Destination destination, String imageUrl)async {
print("---- updating puypint image in db -----");
Database db = await instance.database;
Map<String, dynamic> row = {
"buypoint_image": imageUrl
};
return await db.update(
"destination",
row,
where: 'location_id = ?',
whereArgs: [destination.location_id!]
);
}
Future<int> updateAction(Destination destination, bool checkin)async { Future<int> updateAction(Destination destination, bool checkin)async {
Database db = await instance.database; Database db = await instance.database;
int act = checkin == false ? 0 : 1; int act = checkin == false ? 0 : 1;