added rog local data

This commit is contained in:
Mohamed Nouffer
2022-11-14 22:22:41 +05:30
parent 78970ef5c3
commit 22a17e108c
10 changed files with 369 additions and 239 deletions

View File

@ -70,6 +70,10 @@ class DestinationController extends GetxController {
int chekcs = 0;
var rogaining_counted = false.obs;
String getFormatedTime(DateTime datetime){
return DateFormat('yyyy-MM-dd HH:mm:ss').format(datetime);
}
Destination festuretoDestination(GeoJsonFeature fs){
GeoJsonMultiPoint mp = fs.geometry as GeoJsonMultiPoint;
LatLng pt = LatLng(mp.geoSerie!.geoPoints[0].latitude, mp.geoSerie!.geoPoints[0].longitude);
@ -278,96 +282,6 @@ class DestinationController extends GetxController {
}
}
// 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;
// });
// }
// }
// 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;
// }
// },
// );
// }
void resetRogaining(){
currentSelectedDestinations.forEach((element) {
deleteDestination(element);
@ -479,19 +393,6 @@ class DestinationController extends GetxController {
print("--- made checkin ${df.location_id} ----");
makeCheckin(df, true, "");
}
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} ---------");
});
is_in_rog.value = true;
}
@ -598,10 +499,35 @@ class DestinationController extends GetxController {
locationPermission.add(err.toString());
}
ever(indexController.connectionStatusName, connectionChanged);
super.onInit();
}
void connectionChanged(String val) {
print('----- %%%%%%%%%%%%%%%%%%%%% ----- ${val}');
if(val == "wifi" || val == "mobile"){
String _token = indexController.currentUser[0]["token"];
DatabaseHelper db = DatabaseHelper.instance;
db.allRogianing().then((value){
value.forEach((e) {
if(e.rog_action_type == 0){
ExternalService().StartRogaining();
}
else if(e.rog_action_type == 1){
var datetime = new DateTime.fromMicrosecondsSinceEpoch(e.checkintime!);
ExternalService().makeCheckpoint(e.user_id!, _token, getFormatedTime(datetime), e.team_name!, e.cp_number!, e.event_code!, e.image!);
}
else if(e.rog_action_type == 2){
var datetime = new DateTime.fromMicrosecondsSinceEpoch(e.checkintime!);
ExternalService().makeGoal(e.user_id!, _token, e.team_name!, e.image!, getFormatedTime(datetime), e.event_code!);
}
});
});
}
}
void checkPermission() async {
LocationPermission permission = await Geolocator.checkPermission();
if (permission != LocationPermission.whileInUse ||

View File

@ -178,13 +178,8 @@ class DestnationPage extends StatelessWidget {
icon: Icon(Icons.accessibility),
),
),
// TextButton(
// onPressed: (){
// //ExternalService().StartRogaining('team_name', "2222");
// //destinationController.openCamera(context);
// Get.toNamed(AppPages.CAMERA_PAGE);
// },
// child: Icon(Icons.ac_unit),
// Obx(() =>
// Text(indexController.connectionStatusName.value)
// ),
Obx(() =>
ToggleButtons(

View File

@ -1,6 +1,8 @@
import 'dart:async';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map/plugin_api.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
@ -64,6 +66,11 @@ class IndexController extends GetxController {
late Worker _ever;
ConnectivityResult connectionStatus = ConnectivityResult.none;
var connectionStatusName = "".obs;
final Connectivity _connectivity = Connectivity();
late StreamSubscription<ConnectivityResult> _connectivitySubscription;
void toggleMode(){
if(mode.value==0){
mode += 1;
@ -123,9 +130,35 @@ class IndexController extends GetxController {
//loadSubPerfFor("9");
});
}
_connectivitySubscription = _connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
super.onInit();
}
@override
void onClose() {
_connectivitySubscription.cancel();
super.onClose();
}
Future<void> _updateConnectionStatus(ConnectivityResult result) async {
connectionStatus = result;
connectionStatusName.value = result.name;
}
Future<void> initConnectivity() async {
late ConnectivityResult result;
// Platform messages may fail, so we use a try/catch PlatformException.
try {
result = await _connectivity.checkConnectivity();
} on PlatformException catch (e) {
print('Couldn\'t check connectivity status --- $e');
return;
}
return _updateConnectionStatus(result);
}
LatLngBounds boundsFromLatLngList(List<LatLng> list) {
double? x0, x1, y0, y1;