fixed GPS issue
This commit is contained in:
@ -3,6 +3,7 @@ import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||||
import 'package:rogapp/pages/index/index_binding.dart';
|
import 'package:rogapp/pages/index/index_binding.dart';
|
||||||
|
import 'package:rogapp/pages/index/index_controller.dart';
|
||||||
import 'package:rogapp/routes/app_pages.dart';
|
import 'package:rogapp/routes/app_pages.dart';
|
||||||
import 'package:rogapp/utils/string_values.dart';
|
import 'package:rogapp/utils/string_values.dart';
|
||||||
// import 'package:is_lock_screen/is_lock_screen.dart';
|
// import 'package:is_lock_screen/is_lock_screen.dart';
|
||||||
@ -58,7 +59,9 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
|||||||
case AppLifecycleState.resumed:
|
case AppLifecycleState.resumed:
|
||||||
print("RESUMED");
|
print("RESUMED");
|
||||||
DestinationController destinationController = Get.find<DestinationController>();
|
DestinationController destinationController = Get.find<DestinationController>();
|
||||||
destinationController.initGPS();
|
if(destinationController.positionStream == null){
|
||||||
|
destinationController.startGPSTimer();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case AppLifecycleState.inactive:
|
case AppLifecycleState.inactive:
|
||||||
print("INACTIVE");
|
print("INACTIVE");
|
||||||
|
|||||||
@ -52,6 +52,10 @@ class DestinationController extends GetxController {
|
|||||||
List<String> gps = <String>["-- stating --"].obs;
|
List<String> gps = <String>["-- stating --"].obs;
|
||||||
List<String> locationPermission = <String>[" -- starting -- "].obs;
|
List<String> locationPermission = <String>[" -- starting -- "].obs;
|
||||||
|
|
||||||
|
StreamSubscription<Position>? positionStream;
|
||||||
|
|
||||||
|
Timer? _GPStimer;
|
||||||
|
|
||||||
var travelMode = 0.obs;
|
var travelMode = 0.obs;
|
||||||
|
|
||||||
bool skip_gps = false;
|
bool skip_gps = false;
|
||||||
@ -324,7 +328,8 @@ class DestinationController extends GetxController {
|
|||||||
|
|
||||||
db.deleteAllDestinations().then((value) {
|
db.deleteAllDestinations().then((value) {
|
||||||
PopulateDestinations();
|
PopulateDestinations();
|
||||||
initGPS();
|
startGPSTimer();
|
||||||
|
//initGPS();
|
||||||
});
|
});
|
||||||
|
|
||||||
// currentSelectedDestinations.forEach((element) {
|
// currentSelectedDestinations.forEach((element) {
|
||||||
@ -517,10 +522,10 @@ class DestinationController extends GetxController {
|
|||||||
|
|
||||||
if (defaultTargetPlatform == TargetPlatform.android) {
|
if (defaultTargetPlatform == TargetPlatform.android) {
|
||||||
locationSettings = AndroidSettings(
|
locationSettings = AndroidSettings(
|
||||||
accuracy: LocationAccuracy.bestForNavigation,
|
accuracy: LocationAccuracy.high,
|
||||||
distanceFilter: 0,
|
distanceFilter: 1,
|
||||||
forceLocationManager: true,
|
forceLocationManager: true,
|
||||||
intervalDuration: const Duration(seconds: 1),
|
intervalDuration: const Duration(seconds: 3),
|
||||||
//(Optional) Set foreground notification config to keep the app alive
|
//(Optional) Set foreground notification config to keep the app alive
|
||||||
//when going to the background
|
//when going to the background
|
||||||
foregroundNotificationConfig: const ForegroundNotificationConfig(
|
foregroundNotificationConfig: const ForegroundNotificationConfig(
|
||||||
@ -532,7 +537,7 @@ class DestinationController extends GetxController {
|
|||||||
} else if (defaultTargetPlatform == TargetPlatform.iOS ||
|
} else if (defaultTargetPlatform == TargetPlatform.iOS ||
|
||||||
defaultTargetPlatform == TargetPlatform.macOS) {
|
defaultTargetPlatform == TargetPlatform.macOS) {
|
||||||
locationSettings = AppleSettings(
|
locationSettings = AppleSettings(
|
||||||
accuracy: LocationAccuracy.bestForNavigation,
|
accuracy: LocationAccuracy.high,
|
||||||
activityType: ActivityType.fitness,
|
activityType: ActivityType.fitness,
|
||||||
distanceFilter: 0,
|
distanceFilter: 0,
|
||||||
pauseLocationUpdatesAutomatically: false,
|
pauseLocationUpdatesAutomatically: false,
|
||||||
@ -546,8 +551,7 @@ class DestinationController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
StreamSubscription<Position> positionStream =
|
positionStream = Geolocator.getPositionStream(locationSettings: locationSettings)
|
||||||
Geolocator.getPositionStream(locationSettings: locationSettings)
|
|
||||||
.listen((Position? position) {
|
.listen((Position? position) {
|
||||||
current_lat = position != null ? position.latitude : 0;
|
current_lat = position != null ? position.latitude : 0;
|
||||||
current_lon = position != null ? position.longitude : 0;
|
current_lon = position != null ? position.longitude : 0;
|
||||||
@ -565,9 +569,9 @@ class DestinationController extends GetxController {
|
|||||||
//String user_id = indexController.currentUser[0]["user"]["id"].toString();
|
//String user_id = indexController.currentUser[0]["user"]["id"].toString();
|
||||||
//TrackingService.addTrack(user_id, position!.latitude, position.longitude).then((val){
|
//TrackingService.addTrack(user_id, position!.latitude, position.longitude).then((val){
|
||||||
//print("---- postion is ${position.latitude}, ${position.longitude}");
|
//print("---- postion is ${position.latitude}, ${position.longitude}");
|
||||||
gps.clear();
|
//gps.clear();
|
||||||
gps.add(
|
//gps.add(
|
||||||
"-- lat : ${position.latitude}, lon : ${position.longitude} --");
|
// "-- lat : ${position.latitude}, lon : ${position.longitude} --");
|
||||||
checkForCheckin(position.latitude, position.longitude);
|
checkForCheckin(position.latitude, position.longitude);
|
||||||
print("--- call check checkin");
|
print("--- call check checkin");
|
||||||
print("---- skip gps is ${skip_gps.toString()} ----");
|
print("---- skip gps is ${skip_gps.toString()} ----");
|
||||||
@ -583,10 +587,44 @@ class DestinationController extends GetxController {
|
|||||||
ever(indexController.connectionStatusName, connectionChanged);
|
ever(indexController.connectionStatusName, connectionChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void startGPSTimer() {
|
||||||
|
// If a timer is already running, we first cancel it
|
||||||
|
_GPStimer?.cancel();
|
||||||
|
|
||||||
|
// Start a new timer that fires every 3 seconds
|
||||||
|
_timer = Timer.periodic(Duration(seconds: 3), (timer) async {
|
||||||
|
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
|
||||||
|
|
||||||
|
if (is_gps_selected.value) {
|
||||||
|
double czoom = indexController.rogMapController.zoom;
|
||||||
|
indexController.rogMapController
|
||||||
|
.move(LatLng(position.latitude, position.longitude), czoom);
|
||||||
|
checkForCheckin(position.latitude, position.longitude);
|
||||||
|
print("--- call check checkin");
|
||||||
|
print("---- skip gps is ${skip_gps.toString()} ----");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopGPSTimer() {
|
||||||
|
_GPStimer?.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onClose() {
|
||||||
|
positionStream?.cancel();
|
||||||
|
_GPStimer?.cancel();
|
||||||
|
super.onClose();
|
||||||
|
super.onClose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() async {
|
void onInit() async {
|
||||||
initGPS();
|
//initGPS();
|
||||||
|
startGPSTimer();
|
||||||
super.onInit();
|
super.onInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,7 @@ dependencies:
|
|||||||
sqflite: ^2.0.1
|
sqflite: ^2.0.1
|
||||||
get: ^4.6.5
|
get: ^4.6.5
|
||||||
flutter_map: any
|
flutter_map: any
|
||||||
geolocator: ^9.0.1
|
geolocator: ^9.0.2
|
||||||
permission_handler: ^10.0.0
|
permission_handler: ^10.0.0
|
||||||
google_api_availability: ^5.0.0
|
google_api_availability: ^5.0.0
|
||||||
tuple: ^2.0.0
|
tuple: ^2.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user