Files
rog_app/lib/pages/destination/destination_controller.dart

722 lines
25 KiB
Dart
Raw Normal View History

2022-05-12 02:17:08 +05:30
2022-06-14 14:37:59 +05:30
import 'dart:convert';
2022-10-12 21:46:17 +05:30
import 'dart:io';
2022-06-14 14:37:59 +05:30
2022-10-12 21:46:17 +05:30
import 'package:camera_camera/camera_camera.dart';
2022-06-04 20:16:29 +05:30
import 'package:flutter/foundation.dart';
2022-05-12 02:17:08 +05:30
import 'package:flutter/material.dart';
2022-06-14 14:37:59 +05:30
import 'package:geojson/geojson.dart';
2022-06-04 20:16:29 +05:30
import 'package:geolocator/geolocator.dart';
2022-05-12 02:17:08 +05:30
import 'package:get/get.dart';
2022-06-14 14:37:59 +05:30
import 'package:latlong2/latlong.dart';
2022-10-12 21:46:17 +05:30
import 'package:rogapp/model/Rogaining.dart';
2022-07-09 22:51:34 +05:30
import 'package:rogapp/model/destination.dart';
2022-10-30 21:43:29 +05:30
import 'package:rogapp/pages/camera/camera_page.dart';
2022-05-12 02:17:08 +05:30
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
2022-10-12 21:46:17 +05:30
import 'package:rogapp/services/action_service.dart';
2022-05-12 02:17:08 +05:30
import 'package:rogapp/services/destination_service.dart';
2022-10-19 08:53:17 +05:30
import 'package:rogapp/services/external_service.dart';
2022-05-18 19:09:26 +05:30
import 'package:rogapp/services/maxtrix_service.dart';
2022-06-14 14:37:59 +05:30
import 'package:rogapp/services/reacking_service.dart';
2022-07-09 22:51:34 +05:30
import 'package:rogapp/utils/database_helper.dart';
2022-10-30 21:43:29 +05:30
import 'package:rogapp/widgets/bottom_sheet_new.dart';
2022-06-04 20:16:29 +05:30
import 'dart:async';
2022-05-12 02:17:08 +05:30
2022-06-14 14:37:59 +05:30
import 'package:rogapp/widgets/bottom_sheet_widget.dart';
2022-10-12 21:46:17 +05:30
import 'package:sqflite/sqlite_api.dart';
2022-06-14 14:37:59 +05:30
2022-05-12 02:17:08 +05:30
class DestinationController extends GetxController {
2022-06-04 20:16:29 +05:30
late LocationSettings locationSettings;
2022-05-12 02:17:08 +05:30
2022-06-29 18:25:19 +05:30
var destinationCount = 0.obs;
2022-07-09 22:51:34 +05:30
List<Destination> destinations = <Destination>[].obs;
2022-10-12 21:46:17 +05:30
double current_lat = 0.0;
double current_lon = 0.0;
2022-05-25 21:00:10 +05:30
2022-10-30 21:43:29 +05:30
List<Destination> currentSelectedDestinations = <Destination>[].obs;
2022-07-10 23:50:43 +05:30
2022-10-30 21:43:29 +05:30
var is_in_checkin = false.obs;
2022-10-12 21:46:17 +05:30
var is_in_rog = false.obs;
2022-10-30 21:43:29 +05:30
var is_at_start = false.obs;
var is_at_goal = false.obs;
//List<Rogaining> rogainings = <Rogaining>[].obs;
2022-10-12 21:46:17 +05:30
2022-06-14 14:37:59 +05:30
bool checking_in = false;
2022-10-30 21:43:29 +05:30
var is_gps_selected = true.obs;
2022-06-14 14:37:59 +05:30
BuildContext? context;
2022-07-20 15:57:40 +05:30
List<String> gps = <String>["-- stating --"].obs;
List<String> locationPermission = <String>[" -- starting -- "].obs;
2022-09-22 20:36:56 +05:30
var travelMode = 0.obs;
2022-10-30 21:43:29 +05:30
bool skip_gps = false;
2022-07-20 15:57:40 +05:30
2022-05-18 19:09:26 +05:30
Map<String, dynamic> matrix = {};
2022-05-12 02:17:08 +05:30
2022-10-12 21:46:17 +05:30
final photos = <File>[].obs;
2022-05-12 02:17:08 +05:30
final IndexController indexController = Get.find<IndexController>();
2022-10-12 21:46:17 +05:30
Timer? _timer;
2022-10-30 21:43:29 +05:30
int _start = 0;
2022-11-01 23:47:35 +05:30
int chekcs = 0;
2022-10-12 21:46:17 +05:30
var rogaining_counted = false.obs;
2022-10-30 21:43:29 +05:30
Destination festuretoDestination(GeoJsonFeature fs){
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude);
//print("----- ${indexController.currentFeature[0].properties} -----");
return Destination(
name: fs.properties!["location_name"],
address: fs.properties!["address"],
phone: fs.properties!["phone"],
email: fs.properties!["email"],
webcontents: fs.properties!["webcontents"],
videos: fs.properties!["videos"],
category: fs.properties!["category"],
series: 1,
lat: pt.latitude,
lon: pt.longitude,
location_id: fs.properties!["location_id"],
list_order: 1,
photos: fs.properties!["photos"],
checkin_radious: fs.properties!["checkin_radius"],
auto_checkin: fs.properties!["auto_checkin"] == true ? 1 : 0,
cp: fs.properties!["cp"],
checkin_point: fs.properties!["checkin_point"],
buy_point: fs.properties!["buy_point"],
selected: false,
checkedin: false,
hidden_location: fs.properties!["hidden_location"] == true ?1 : 0
);
}
void startTimerLocation(GeoJsonFeature fs, double distance) {
print("---- in startTimer ----");
2022-11-02 22:47:49 +05:30
//skip_gps = true;
2022-10-30 21:43:29 +05:30
double checkin_radious = fs.properties!['checkin_radius'] ?? double.infinity;
if(checkin_radious >= distance){
2022-11-01 23:47:35 +05:30
indexController.currentFeature.clear();
2022-10-30 21:43:29 +05:30
Destination d = festuretoDestination(fs);
2022-11-01 23:47:35 +05:30
for(Destination de in destinations){
if(de.location_id == d.location_id){
d = de;
break;
}
}
indexController.currentFeature.add(fs);
2022-10-30 21:43:29 +05:30
print("---- before calling startTimer ----");
startTimer(d, distance);
}
}
void startTimer(Destination d, double distance) async {
skip_gps = true;
print("---- in startTimer ----");
double checkin_radious = d.checkin_radious ?? double.infinity;
bool auto_checkin = d.auto_checkin == 0 ? false : true;
bool location_already_checked_in = d.checkedin ?? false;
bool isUser_logged_in = indexController.currentUser.length > 0 ? true : false;
//make current destination
print("---- checkin_radious ${checkin_radious} ----");
print("---- distance ${distance} ----");
if(checkin_radious >= distance){
//currentSelectedDestinations.add(d);
indexController.currentDestinationFeature.clear();
indexController.currentDestinationFeature.add(d);
print("---- checked in as ${indexController.currentDestinationFeature[0].checkedin.toString()} ----");
}
else {
skip_gps = false;
return;
}
DatabaseHelper db = DatabaseHelper.instance;
List<Destination> ds = await db.getDestinationByLatLon(d.lat!, d.lon!);
if(ds.isEmpty){
print("----- in location popup cp - ${d.cp}----");
if(d.cp == -1){
2022-11-01 23:47:35 +05:30
chekcs = 1;
2022-10-30 21:43:29 +05:30
//start
print("---- in start -----");
2022-11-01 23:47:35 +05:30
chekcs = 1;
2022-10-30 21:43:29 +05:30
is_at_start.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => BottomSheetNew())
).whenComplete((){
skip_gps = false;
2022-11-01 23:47:35 +05:30
chekcs = 0;
2022-10-30 21:43:29 +05:30
is_at_start.value = false;
});
}
else
{
print("----- in location popup checkin cp - ${d.cp}----");
2022-11-02 22:47:49 +05:30
chekcs = 2;
2022-10-30 21:43:29 +05:30
//is_in_checkin.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => BottomSheetNew())
).whenComplete((){
skip_gps = false;
2022-11-02 22:47:49 +05:30
chekcs =0;
2022-10-30 21:43:29 +05:30
is_in_checkin.value = false;
});
}
}
print("---- location checkin radious ${d.checkin_radious} ----");
2022-11-01 23:47:35 +05:30
print("---- already checked in ${location_already_checked_in} ----");
2022-10-30 21:43:29 +05:30
if(checkin_radious >= distance && location_already_checked_in == false){
if(auto_checkin){
if(!checking_in){
makeCheckin(d, true);
if(d.cp != -1){
rogaining_counted.value =true;
}
skip_gps = false;
}
}
else{
// ask for checkin
2022-11-01 23:47:35 +05:30
if(d.hidden_location != null && d.hidden_location ==true && is_in_rog.value == true && d.cp != -1){
2022-11-02 22:47:49 +05:30
chekcs = 3;
2022-10-30 21:43:29 +05:30
is_in_checkin.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => CameraPage())
).whenComplete((){
skip_gps = false;
2022-11-01 23:47:35 +05:30
chekcs = 0;
2022-10-30 21:43:29 +05:30
is_in_checkin.value = false;
});
}
2022-11-01 23:47:35 +05:30
else if(is_in_rog.value == true && d.cp != -1){
2022-11-02 22:47:49 +05:30
chekcs = 4;
2022-10-30 21:43:29 +05:30
is_in_checkin.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => BottomSheetNew())
).whenComplete((){
skip_gps = false;
2022-11-01 23:47:35 +05:30
chekcs = 0;
2022-10-30 21:43:29 +05:30
is_in_checkin.value = false;
});
}
}
}
2022-11-01 23:47:35 +05:30
print("---- cp --- ${d.cp} -----");
print("--- at goal ${is_at_goal} ---");
print("--- rog counted ${rogaining_counted} ---");
print("--- loc already checked in ${location_already_checked_in} ---");
2022-10-30 21:43:29 +05:30
if(isUser_logged_in && d.cp == -1 && location_already_checked_in){
//check for rogaining
if(is_at_goal.value == false && rogaining_counted.value){
//goal
print("---- in goal -----");
2022-11-02 22:47:49 +05:30
chekcs = 5;
2022-10-30 21:43:29 +05:30
is_at_goal.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => CameraPage())
).whenComplete((){
skip_gps = false;
2022-11-01 23:47:35 +05:30
chekcs = 0;
2022-10-30 21:43:29 +05:30
is_at_goal.value = false;
});
}
else if(is_in_rog.value == false){
//start
print("---- in start -----");
2022-11-02 22:47:49 +05:30
chekcs = 6;
2022-10-30 21:43:29 +05:30
is_at_start.value = true;
showModalBottomSheet(context: Get.context!, isScrollControlled: true,
builder:((context) => BottomSheetNew())
).whenComplete((){
2022-11-01 23:47:35 +05:30
print("----- finished start -------");
2022-10-30 21:43:29 +05:30
skip_gps = false;
2022-11-01 23:47:35 +05:30
chekcs = 0;
2022-10-30 21:43:29 +05:30
is_at_start.value = false;
});
}
}
2022-11-01 23:47:35 +05:30
print("---- _chekcs ${chekcs} ----");
if(chekcs == 0){
2022-10-30 21:43:29 +05:30
skip_gps = false;
}
}
2022-11-01 23:47:35 +05:30
// void startTimer2(Destination d, double distance) {
// skip_gps = true;
// print("---- in startTimer ----");
// double checkin_radious = d.checkin_radious ?? double.infinity;
// bool auto_checkin = d.auto_checkin == 0 ? false : true;
// bool location_already_checked_id = d.checkedin ?? false;
// bool isUser_logged_in = indexController.currentUser.length > 0 ? true : false;
// //make current destination
// print("---- checkin_radious ${checkin_radious} ----");
// print("---- distance ${distance} ----");
// if(checkin_radious >= distance){
// //currentSelectedDestinations.add(d);
// indexController.currentDestinationFeature.clear();
// indexController.currentDestinationFeature.add(d);
// print("---- checked in as ${indexController.currentDestinationFeature[0].checkedin.toString()} ----");
// }
// const oneSec = const Duration(seconds: 1);
// _timer = Timer.periodic(
// oneSec,
// (Timer timer) {
// if (_start == 0) {
// //make checkin
// print("---- location checkin radious ${d.checkin_radious} ----");
// print("---- already checked in ${location_already_checked_id} ----");
// if(checkin_radious >= distance && location_already_checked_id == false){
// if(auto_checkin){
// if(!checking_in){
// makeCheckin(d, true);
// if(d.cp != -1){
// rogaining_counted.value =true;
// }
// skip_gps = false;
// }
// }
// else{
// // ask for checkin
// _chekcs = 1;
// is_in_checkin.value = true;
// showModalBottomSheet(context: Get.context!, isScrollControlled: true,
// builder:((context) => BottomSheetNew())
// ).whenComplete((){
// skip_gps = false;
// _chekcs = 0;
// is_in_checkin.value = false;
// });
// }
// }
2022-10-30 21:43:29 +05:30
2022-11-01 23:47:35 +05:30
// if(isUser_logged_in && d.cp == -1 && location_already_checked_id){
// //check for rogaining
// if(is_at_goal.value == false && rogaining_counted.value){
// //goal
// print("---- in goal -----");
// _chekcs = 1;
// is_at_goal.value = true;
// showModalBottomSheet(context: Get.context!, isScrollControlled: true,
// builder:((context) => BottomSheetNew())
// ).whenComplete((){
// skip_gps = false;
// _chekcs = 0;
// is_at_goal.value = false;
// });
// }
// else if(is_in_rog.value == false){
// //start
// print("---- in start -----");
// _chekcs = 1;
// is_at_start.value = true;
// showModalBottomSheet(context: Get.context!, isScrollControlled: true,
// builder:((context) => BottomSheetNew())
// ).whenComplete((){
// skip_gps = false;
// _chekcs = 0;
// is_at_start.value = false;
// });
// }
// }
// timer.cancel();
// } else {
// _start--;
// }
// print("---- _chekcs ${_chekcs} ----");
// if(_chekcs == 0){
// skip_gps = false;
// }
// },
// );
// }
2022-10-12 21:46:17 +05:30
2022-10-30 21:43:29 +05:30
void resetRogaining(){
is_in_checkin.value = false;
is_in_rog.value = false;
is_at_start.value = false;
is_at_goal.value = false;
_start = 0;
2022-11-01 23:47:35 +05:30
chekcs = 0;
2022-10-30 21:43:29 +05:30
rogaining_counted.value = false;
}
2022-10-12 21:46:17 +05:30
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(() {});
},
)));
}
2022-09-22 20:36:56 +05:30
void getRoutePoints() {
indexController.routePoints = [];
indexController.routePointLenght.value = 0;
2022-09-29 15:32:33 +05:30
DestinationService.getDestinationLine(destinations, matrix)?.then((value){
2022-09-22 20:36:56 +05:30
indexController.routePoints = value;
indexController.routePointLenght.value = indexController.routePoints.length;
});
}
2022-06-14 14:37:59 +05:30
2022-10-30 21:43:29 +05:30
Future<Destination?> getDestinationForLatLong(double lat, double long)async {
2022-06-14 14:37:59 +05:30
for(final d in destinations){
2022-07-09 22:51:34 +05:30
if(lat == d.lat && long == d.lon){
return d;
2022-06-14 14:37:59 +05:30
}
}
}
2022-10-30 21:43:29 +05:30
void checkForCheckin(double la, double ln){
2022-10-12 21:46:17 +05:30
2022-10-30 21:43:29 +05:30
print("--- skip_gps ---- ${skip_gps}----");
2022-07-14 23:10:24 +05:30
2022-06-14 14:37:59 +05:30
for(final d in destinations){
2022-07-20 15:57:40 +05:30
2022-10-30 21:43:29 +05:30
print("--- check checkin for--loc_id- ${d.location_id}----");
2022-10-19 08:53:17 +05:30
2022-07-20 15:57:40 +05:30
double lat = d.lat!;
double lon = d.lon!;
LatLng p = LatLng(lat, lon);
2022-10-30 21:43:29 +05:30
getDestinationForLatLong(lat, lon).then((value){
2022-07-20 15:57:40 +05:30
var distance = Distance();
double dist = distance.as(LengthUnit.Meter, LatLng(lat, lon), LatLng(la, ln));
2022-10-30 21:43:29 +05:30
//double checkin_radious = value!.checkin_radious ?? double.infinity;
//bool auto_checkin = value.auto_checkin == 0 ? false : true;
//bool location_already_checked_id = d.checkedin ?? false;
// print("-----rogaining_counted---${rogaining_counted.value}-----");
// print("-----is_in_rog---${is_in_rog}-----");
// print("-----dist is ---${dist}-----");
//print("----- ${indexController.currentUser} ----");
if(dist <= 250 && skip_gps == false){
//near a destination
print("---- time with ${d.location_id} ----");
2022-10-12 21:46:17 +05:30
startTimer(d, dist);
}
2022-10-30 21:43:29 +05:30
});
2022-10-12 21:46:17 +05:30
2022-10-30 21:43:29 +05:30
}
2022-07-20 15:57:40 +05:30
2022-10-30 21:43:29 +05:30
//check for location in bounds
for(GeoJsonFeature fs in indexController.locations[0].collection){
2022-07-20 15:57:40 +05:30
2022-10-30 21:43:29 +05:30
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude);
2022-07-20 15:57:40 +05:30
2022-10-30 21:43:29 +05:30
double lat_fs = pt.latitude;
double lon_fs = pt.longitude;
LatLng p_fs = LatLng(lat_fs, lon_fs);
var distance_fs = Distance();
double dist_fs = distance_fs.as(LengthUnit.Meter, LatLng(lat_fs, lon_fs), LatLng(la, ln));
2022-06-14 14:37:59 +05:30
2022-10-30 21:43:29 +05:30
if(dist_fs <= 250 && skip_gps == false){
//near a location
print("---- before call startTimerLocation ----");
startTimerLocation(fs, dist_fs);
}
2022-06-14 14:37:59 +05:30
}
}
2022-10-30 21:43:29 +05:30
void addToRogaining(double lat, double lon, int destination_id) async {
DatabaseHelper db = DatabaseHelper.instance;
2022-11-01 23:47:35 +05:30
List<Destination> d = await db.getDestinationById(destination_id);
if(d.isEmpty){
Destination df = festuretoDestination(indexController.currentFeature[0]);
print("--- made checkin ${df.location_id} ----");
2022-10-30 21:43:29 +05:30
makeCheckin(df, true);
}
2022-10-12 21:46:17 +05:30
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
);
db.insertRogaining(rog).then((value){
print("----- inserted value ${value} ---------");
});
2022-11-01 23:47:35 +05:30
is_in_rog.value = true;
2022-10-12 21:46:17 +05:30
}
2022-11-02 22:47:49 +05:30
void makeCheckin(Destination destination, bool action, {String imageurl = ""}) async {
2022-10-19 08:53:17 +05:30
// print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ressssss ${action}@@@@@@@@@@@");
2022-11-01 23:47:35 +05:30
DatabaseHelper db = DatabaseHelper.instance;
List<Destination> ddd = await db.getDestinationByLatLon(destination.lat!, destination.lon!);
if(ddd.isEmpty){
destination.checkedin = true;
await db.insertDestination(destination);
}
//int res = await db.updateAction(destination, action);
2022-10-12 21:46:17 +05:30
2022-11-01 23:47:35 +05:30
PopulateDestinations();
/// post to NATNAT
if(indexController.currentUser.length > 0){
int cp_num = int.parse(destination.cp!.toString());
String _team = indexController.currentUser[0]["user"]["team_name"];
String _event_code = indexController.currentUser[0]["user"]["event_code"];
2022-11-02 22:47:49 +05:30
ExternalService().makeCheckpoint(_team, cp_num, _event_code, imageurl).then((value){
2022-11-01 23:47:35 +05:30
print("------Ext service check point ${value} ------");
});
}
2022-07-14 23:10:24 +05:30
}
2022-06-14 14:37:59 +05:30
2022-05-12 02:17:08 +05:30
@override
2022-07-14 23:10:24 +05:30
void onInit() async {
2022-07-20 15:57:40 +05:30
checkPermission();
2022-05-12 02:17:08 +05:30
PopulateDestinations();
2022-07-14 23:10:24 +05:30
2022-07-23 19:28:35 +05:30
//print("------ in iniit");
2022-06-27 12:15:54 +05:30
2022-07-09 22:51:34 +05:30
if (defaultTargetPlatform == TargetPlatform.android) {
locationSettings = AndroidSettings(
2022-07-20 15:57:40 +05:30
accuracy: LocationAccuracy.bestForNavigation,
2022-07-16 00:08:00 +05:30
distanceFilter: 00,
2022-07-09 22:51:34 +05:30
forceLocationManager: true,
2022-10-30 21:43:29 +05:30
intervalDuration: const Duration(seconds: 10),
2022-07-09 22:51:34 +05:30
//(Optional) Set foreground notification config to keep the app alive
//when going to the background
foregroundNotificationConfig: const ForegroundNotificationConfig(
notificationText:
"Example app will continue to receive your location even when you aren't using it",
notificationTitle: "Running in Background",
enableWakeLock: true,
)
);
} else if (defaultTargetPlatform == TargetPlatform.iOS || defaultTargetPlatform == TargetPlatform.macOS) {
locationSettings = AppleSettings(
2022-07-20 15:57:40 +05:30
accuracy: LocationAccuracy.bestForNavigation,
2022-07-09 22:51:34 +05:30
activityType: ActivityType.fitness,
2022-10-30 21:43:29 +05:30
distanceFilter: 30,
2022-07-09 22:51:34 +05:30
pauseLocationUpdatesAutomatically: false,
// Only set to true if our app will be started up in the background.
showBackgroundLocationIndicator: true
);
} else {
locationSettings = LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 30,
);
}
2022-06-29 18:25:19 +05:30
2022-07-20 15:57:40 +05:30
try {
StreamSubscription<Position> positionStream = Geolocator.getPositionStream(locationSettings: locationSettings).listen(
(Position? position) {
2022-10-12 21:46:17 +05:30
current_lat = position != null ? position.latitude : 0;
current_lon = position != null ? position.longitude : 0;
2022-10-30 21:43:29 +05:30
if(is_gps_selected.value){
2022-07-20 15:57:40 +05:30
double czoom = indexController.rogMapController!.zoom;
indexController.rogMapController!.move(LatLng(position!.latitude, position!.longitude), czoom);
//String user_id = indexController.currentUser[0]["user"]["id"].toString();
//TrackingService.addTrack(user_id, position!.latitude, position.longitude).then((val){
2022-07-23 19:28:35 +05:30
//print("---- postion is ${position.latitude}, ${position.longitude}");
2022-07-20 15:57:40 +05:30
gps.clear();
gps.add("-- lat : ${position.latitude}, lon : ${position.longitude} --");
checkForCheckin(position!.latitude, position.longitude);
2022-10-30 21:43:29 +05:30
print("--- call check checkin");
print("---- skip gps is ${skip_gps.toString()} ----");
2022-07-20 15:57:40 +05:30
//});
}
2022-07-23 19:28:35 +05:30
//print(position == null ? 'Unknown' : 'current position is ${position.latitude.toString()}, ${position.longitude.toString()}');
2022-07-20 15:57:40 +05:30
});
} catch (err){
locationPermission.clear();
locationPermission.add(err.toString());
}
2022-06-29 18:25:19 +05:30
2022-09-22 20:36:56 +05:30
super.onInit();
2022-06-04 20:16:29 +05:30
2022-05-12 02:17:08 +05:30
}
2022-07-14 23:10:24 +05:30
void checkPermission() async {
LocationPermission permission = await Geolocator.checkPermission();
if (permission != LocationPermission.whileInUse ||
permission != LocationPermission.always) {
2022-07-20 15:57:40 +05:30
locationPermission.clear();
locationPermission.add(permission.name);
2022-07-14 23:10:24 +05:30
permission = await Geolocator.requestPermission();
}
}
2022-10-12 21:46:17 +05:30
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;
}
2022-07-10 23:50:43 +05:30
void deleteDestination(Destination d){
//int id = destinations[index].location_id!;
2022-07-09 22:51:34 +05:30
//print("---- index ${destinations[index].location_id!}-----");
2022-10-30 21:43:29 +05:30
for(Destination ss in destinations){
2022-07-10 23:50:43 +05:30
if(ss.location_id == d.location_id){
2022-10-30 21:43:29 +05:30
destinations.remove(ss);
2022-07-10 23:50:43 +05:30
break;
}
}
2022-07-09 22:51:34 +05:30
DatabaseHelper db = DatabaseHelper.instance;
2022-07-10 23:50:43 +05:30
db.deleteDestination(d.location_id!).then((value){
2022-05-25 21:00:10 +05:30
PopulateDestinations();
});
2022-07-09 22:51:34 +05:30
}
2022-09-23 18:40:17 +05:30
void deleteAllDestinations(){
DatabaseHelper db = DatabaseHelper.instance;
db.deleteAllDestinations().then((value){
PopulateDestinations();
});
}
2022-07-09 22:51:34 +05:30
// ---------- database ------------------///
void addDestinations(Destination dest){
2022-10-30 21:43:29 +05:30
print('------ destination controller in add destination ${dest.checkin_radious} ---- :::::');
2022-07-10 23:50:43 +05:30
2022-07-09 22:51:34 +05:30
DatabaseHelper db = DatabaseHelper.instance;
db.getDestinationByLatLon(dest.lat!, dest.lon!).then((value){
if(value.isNotEmpty){
db.deleteDestination(value[0].location_id!).then((value){
db.insertDestination(dest).then((value){
2022-07-10 23:50:43 +05:30
print("----- destination controller deleted and inserted destination id $value ---- :::::");
PopulateDestinations();
2022-07-09 22:51:34 +05:30
});
});
}
else {
db.insertDestination(dest).then((value){
2022-07-10 23:50:43 +05:30
print("----- destination controller added as new ${value}--- :::::");
PopulateDestinations();
2022-07-09 22:51:34 +05:30
});
}
});
2022-05-25 21:00:10 +05:30
}
2022-05-12 02:17:08 +05:30
void PopulateDestinations(){
2022-07-10 23:50:43 +05:30
print("--------- destination controller populsting destinations ----------- ::::::");
2022-07-09 22:51:34 +05:30
DatabaseHelper db = DatabaseHelper.instance;
2022-09-29 15:32:33 +05:30
destinations.clear();
2022-07-09 22:51:34 +05:30
db.getDestinations().then((value){
2022-09-22 20:36:56 +05:30
destinationCount.value = 0;
2022-07-10 23:50:43 +05:30
for(Destination d in value){
2022-10-30 21:43:29 +05:30
print("------ destination controller populating destination-------- ${d.checkedin}-------- :::::");
2022-11-01 23:47:35 +05:30
print("-----populated----- ${d.toMap()}");
2022-07-10 23:50:43 +05:30
destinations.add(d);
}
2022-07-09 22:51:34 +05:30
// destinationCount.value = 0;
2022-07-10 23:50:43 +05:30
print("------ destination controller destinationcount-------- ${destinationCount}-------- :::::");
2022-07-09 22:51:34 +05:30
MatrixService.getDestinations(value).then((mat){
2022-09-22 20:36:56 +05:30
print(" matrix is ------- ${mat}");
2022-07-09 22:51:34 +05:30
matrix = mat;
2022-11-01 23:47:35 +05:30
try{
getRoutePoints();
destinationCount.value = destinations.length;
}
catch(_){
skip_gps = false;
return;
}
2022-09-22 20:36:56 +05:30
2022-07-09 22:51:34 +05:30
});
});
2022-05-12 02:17:08 +05:30
}
2022-06-04 20:16:29 +05:30
2022-05-12 02:17:08 +05:30
2022-09-23 18:40:17 +05:30
void makeOrder(Destination d, int dir){
DatabaseHelper db = DatabaseHelper.instance;
db.updateOrder(d, dir).then((value){
PopulateDestinations();
});
2022-07-09 22:51:34 +05:30
}
void makeNext(Destination pt){
for(int i=0; i<= destinations.length - 1; i++){
Destination p = destinations[i];
if(p.lat == pt.lat && p.lon == pt.lon ){
if(indexController.currentDestinationFeature.isNotEmpty){
indexController.currentDestinationFeature.clear();
}
if(i >= destinations.length - 1 ){
indexController.currentDestinationFeature.add(destinations[0]);
//getAction();
}
else{
indexController.currentDestinationFeature.add(destinations[i + 1]);
//getAction();
}
}
}
}
2022-07-27 19:43:12 +05:30
void makePrevious(Destination pt){
2022-07-09 22:51:34 +05:30
2022-07-27 19:43:12 +05:30
for(int i=0; i<= destinations.length - 1; i++){
Destination p = destinations[i];
2022-07-09 22:51:34 +05:30
2022-07-27 19:43:12 +05:30
if(p.lat == pt.lat && p.lon == pt.lon ){
if(indexController.currentDestinationFeature.isNotEmpty){
indexController.currentDestinationFeature.clear();
}
if(i <= 0){
indexController.currentDestinationFeature.add(destinations[destinations.length -1]);
//getAction();
}
else{
indexController.currentDestinationFeature.add(destinations[i - 1]);
//getAction();
}
}
}
2022-07-09 22:51:34 +05:30
2022-07-27 19:43:12 +05:30
}
2022-07-09 22:51:34 +05:30
2022-05-12 02:17:08 +05:30
}