map updated to 6
This commit is contained in:
145
lib/utils/location_controller.dart
Normal file
145
lib/utils/location_controller.dart
Normal file
@ -0,0 +1,145 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
|
||||
class LocationController extends GetxController {
|
||||
// Reactive variable to hold the current position
|
||||
Rx<Position?> currentPosition = Rx<Position?>(null);
|
||||
|
||||
// Subscription to the position stream
|
||||
StreamSubscription<Position>? positionStream;
|
||||
bool isStreamPaused = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
// Start listening to location updates when the controller is initialized
|
||||
startPositionStream();
|
||||
}
|
||||
|
||||
void startPositionStream() async {
|
||||
// Check for location service and permissions before starting the stream
|
||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
// Use GetX's context to show a dialog
|
||||
Get.dialog(
|
||||
AlertDialog(
|
||||
title: const Text('Location Services Disabled'),
|
||||
content: const Text(
|
||||
'Please enable location services to continue using the app.'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('OK'),
|
||||
onPressed: () {
|
||||
// Close the dialog
|
||||
Get.back();
|
||||
// Optionally, you can direct the user to the settings page
|
||||
// Geolocator.openLocationSettings();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
barrierDismissible: false, // User must tap button to close dialog
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
// Show a dialog if permissions are still denied
|
||||
Get.dialog(
|
||||
AlertDialog(
|
||||
title: const Text('Location Permission Denied'),
|
||||
content: const Text(
|
||||
'This app requires location permissions to function properly. Please enable location permissions in your device settings.'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('OK'),
|
||||
onPressed: () {
|
||||
// Close the dialog
|
||||
Get.back();
|
||||
// Optionally, direct the user to the app settings
|
||||
// Geolocator.openAppSettings();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
barrierDismissible: false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (permission == LocationPermission.deniedForever) {
|
||||
// Show a dialog if permissions are permanently denied
|
||||
Get.dialog(
|
||||
AlertDialog(
|
||||
title: const Text('Location Permission Needed'),
|
||||
content: const Text(
|
||||
'Location permissions have been permanently denied. Please open app settings to enable location permissions.'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('Open Settings'),
|
||||
onPressed: () {
|
||||
// Close the dialog and open app settings
|
||||
Get.back();
|
||||
Geolocator.openAppSettings();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
barrierDismissible: false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set up the location options
|
||||
const locationOptions = LocationSettings(
|
||||
accuracy: LocationAccuracy.bestForNavigation,
|
||||
distanceFilter: 0,
|
||||
timeLimit: Duration(microseconds: 2500),
|
||||
);
|
||||
|
||||
// Start listening to the position stream
|
||||
positionStream =
|
||||
Geolocator.getPositionStream(locationSettings: locationOptions).listen(
|
||||
(Position position) {
|
||||
currentPosition.value = position;
|
||||
}, onError: (e) {
|
||||
// Handle errors or exceptions in the stream
|
||||
// You might want to log this error or use a state to show error messages
|
||||
});
|
||||
|
||||
// Resume stream if it was paused previously
|
||||
if (isStreamPaused) {
|
||||
positionStream?.resume();
|
||||
isStreamPaused = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Method to stop the position stream
|
||||
void stopPositionStream() {
|
||||
if (positionStream != null) {
|
||||
positionStream!.pause();
|
||||
isStreamPaused = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Method to resume the position stream
|
||||
void resumePositionStream() {
|
||||
if (positionStream != null && isStreamPaused) {
|
||||
positionStream!.resume();
|
||||
isStreamPaused = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// Cancel the position stream subscription when the controller is closed
|
||||
positionStream?.cancel();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
import 'package:geojson/geojson.dart';
|
||||
import 'package:geojson_vi/geojson_vi.dart';
|
||||
import 'package:rogapp/model/destination.dart';
|
||||
|
||||
class TextUtils {
|
||||
static String getDisplayTextFeture(GeoJsonFeature f) {
|
||||
static String getDisplayTextFeture(GeoJSONFeature f) {
|
||||
RegExp regex = RegExp(r'([.]*0)(?!.*\d)');
|
||||
String txt = "";
|
||||
// if(f.properties!["cp"] > 0){
|
||||
|
||||
Reference in New Issue
Block a user