added goal feature
This commit is contained in:
@ -1,16 +1,20 @@
|
||||
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:camera_camera/camera_camera.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:geojson/geojson.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:rogapp/model/Rogaining.dart';
|
||||
import 'package:rogapp/model/destination.dart';
|
||||
import 'package:rogapp/pages/index/index_controller.dart';
|
||||
import 'package:rogapp/routes/app_pages.dart';
|
||||
import 'package:rogapp/services/action_service.dart';
|
||||
import 'package:rogapp/services/destination_service.dart';
|
||||
import 'package:rogapp/services/maxtrix_service.dart';
|
||||
import 'package:rogapp/services/reacking_service.dart';
|
||||
@ -18,6 +22,7 @@ import 'package:rogapp/utils/database_helper.dart';
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:rogapp/widgets/bottom_sheet_widget.dart';
|
||||
import 'package:sqflite/sqlite_api.dart';
|
||||
|
||||
class DestinationController extends GetxController {
|
||||
|
||||
@ -26,9 +31,14 @@ class DestinationController extends GetxController {
|
||||
var destinationCount = 0.obs;
|
||||
List<Destination> destinations = <Destination>[].obs;
|
||||
List<Map<String, dynamic>> destination_index_data = <Map<String, dynamic>>[].obs;
|
||||
double current_lat = 0.0;
|
||||
double current_lon = 0.0;
|
||||
|
||||
List<Destination> currentSelectedDestinations = <Destination>[].obs;
|
||||
|
||||
var is_in_rog = false.obs;
|
||||
List<Rogaining> rogainings = <Rogaining>[].obs;
|
||||
|
||||
bool checking_in = false;
|
||||
var isSelected = false.obs;
|
||||
BuildContext? context;
|
||||
@ -41,8 +51,56 @@ class DestinationController extends GetxController {
|
||||
|
||||
Map<String, dynamic> matrix = {};
|
||||
|
||||
final photos = <File>[].obs;
|
||||
|
||||
final IndexController indexController = Get.find<IndexController>();
|
||||
|
||||
Timer? _timer;
|
||||
int _start = 1;
|
||||
var rogaining_counted = false.obs;
|
||||
|
||||
void startTimer(Destination d, double distance) {
|
||||
const oneSec = const Duration(seconds: 1);
|
||||
_timer = Timer.periodic(
|
||||
oneSec,
|
||||
(Timer timer) {
|
||||
if (_start == 0) {
|
||||
if(is_in_rog.value == false){
|
||||
is_in_rog.value = true;
|
||||
addToRogaining(current_lat, current_lon, d.location_id!);
|
||||
Get.snackbar("Rogaining Started ", "Rogaining session started");
|
||||
}
|
||||
else{
|
||||
//finish rogiain
|
||||
//is_in_rog.value = true;
|
||||
if (rogaining_counted.value && distance <=250){
|
||||
Get.toNamed(AppPages.CAMERA_PAGE);
|
||||
}
|
||||
}
|
||||
timer.cancel();
|
||||
} else {
|
||||
_start--;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void openCamera(BuildContext context) {
|
||||
photos.clear();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => CameraCamera(
|
||||
onFile: (file) {
|
||||
photos.add(file);
|
||||
Navigator.pop(context);
|
||||
print("----image file is : ${file}----");
|
||||
//setState(() {});
|
||||
},
|
||||
)));
|
||||
}
|
||||
|
||||
|
||||
void getRoutePoints() {
|
||||
indexController.routePoints = [];
|
||||
indexController.routePointLenght.value = 0;
|
||||
@ -63,7 +121,12 @@ class DestinationController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
checkForCheckin(double la, double ln){
|
||||
// void addToRogaining(Rogaining rog){
|
||||
// DatabaseHelper db = DatabaseHelper.instance;
|
||||
// db.insertRogaining(rog);
|
||||
// }
|
||||
|
||||
checkForCheckin(double la, double ln){
|
||||
|
||||
for(final d in destinations){
|
||||
|
||||
@ -79,6 +142,14 @@ class DestinationController extends GetxController {
|
||||
double rad = value!.checkin_radious ?? double.infinity;
|
||||
bool auto_checkin = value.auto_checkin == 0 ? false : true;
|
||||
|
||||
if(d.cp != -1 && is_in_rog == true){
|
||||
rogaining_counted.value == true;
|
||||
}
|
||||
|
||||
if(d.cp == -1 && dist <= 250 && rogaining_counted.value == false){
|
||||
startTimer(d, dist);
|
||||
}
|
||||
|
||||
indexController.currentDestinationFeature.add(value);
|
||||
//indexController.getAction();
|
||||
|
||||
@ -127,6 +198,22 @@ class DestinationController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
void addToRogaining(double lat, double lon, int destination_id){
|
||||
Rogaining rog = Rogaining(
|
||||
rog_id: null,
|
||||
course_id: 1,
|
||||
user_id: indexController.currentUser[0]['user']['id'],
|
||||
location_id: destination_id,
|
||||
lat: lat,
|
||||
lon:lon,
|
||||
time_stamp: DateTime.now().toUtc().microsecondsSinceEpoch
|
||||
);
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
db.insertRogaining(rog).then((value){
|
||||
print("----- inserted value ${value} ---------");
|
||||
});
|
||||
}
|
||||
|
||||
void makeCheckin(Destination destination, bool action) async {
|
||||
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@");
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
@ -139,6 +226,15 @@ class DestinationController extends GetxController {
|
||||
PopulateDestinations();
|
||||
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ after populating ${res} @@@@@@@@@@@");
|
||||
print("---- database update resulr ------ res : ${res}-------");
|
||||
|
||||
/// post to NATNAT
|
||||
if(indexController.currentUser.length > 0){
|
||||
String cp_num = destination.cp.toString();
|
||||
String team_name = indexController.currentUser[0]['user']['group'];
|
||||
ActionService.postCheckin(cp_num, team_name).then((value){
|
||||
print('------- NATNAT RES ${value} ------------');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -187,6 +283,9 @@ class DestinationController extends GetxController {
|
||||
StreamSubscription<Position> positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen(
|
||||
|
||||
(Position? position) {
|
||||
current_lat = position != null ? position.latitude : 0;
|
||||
current_lon = position != null ? position.longitude : 0;
|
||||
|
||||
if(isSelected.value){
|
||||
double czoom = indexController.rogMapController!.zoom;
|
||||
indexController.rogMapController!.move(LatLng(position!.latitude, position!.longitude), czoom);
|
||||
@ -220,6 +319,19 @@ class DestinationController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Destination? destinationById(int id){
|
||||
Destination? d = null;
|
||||
print("--- target des - ${id} ----");
|
||||
for(Destination ss in destinations){
|
||||
print("--- des - ${ss.location_id} ----");
|
||||
if(ss.location_id == id){
|
||||
d = ss;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
void deleteDestination(Destination d){
|
||||
//int id = destinations[index].location_id!;
|
||||
//print("---- index ${destinations[index].location_id!}-----");
|
||||
|
||||
Reference in New Issue
Block a user