mirror of
https://github.com/FoggedLens/deflock-app.git
synced 2026-07-09 22:18:38 +02:00
fix follow me not turning off
This commit is contained in:
@@ -92,6 +92,8 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|||||||
void _openAddCameraSheet() {
|
void _openAddCameraSheet() {
|
||||||
// Disable follow-me when adding a camera so the map doesn't jump around
|
// Disable follow-me when adding a camera so the map doesn't jump around
|
||||||
setState(() => _followMeMode = FollowMeMode.off);
|
setState(() => _followMeMode = FollowMeMode.off);
|
||||||
|
// Save the disabled follow-me mode
|
||||||
|
MapViewState.saveFollowMeMode(_followMeMode);
|
||||||
|
|
||||||
final appState = context.read<AppState>();
|
final appState = context.read<AppState>();
|
||||||
appState.startAddSession();
|
appState.startAddSession();
|
||||||
@@ -105,6 +107,8 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|||||||
void _openEditCameraSheet() {
|
void _openEditCameraSheet() {
|
||||||
// Disable follow-me when editing a camera so the map doesn't jump around
|
// Disable follow-me when editing a camera so the map doesn't jump around
|
||||||
setState(() => _followMeMode = FollowMeMode.off);
|
setState(() => _followMeMode = FollowMeMode.off);
|
||||||
|
// Save the disabled follow-me mode
|
||||||
|
MapViewState.saveFollowMeMode(_followMeMode);
|
||||||
|
|
||||||
final appState = context.read<AppState>();
|
final appState = context.read<AppState>();
|
||||||
final session = appState.editSession!; // should be non-null when this is called
|
final session = appState.editSession!; // should be non-null when this is called
|
||||||
@@ -167,6 +171,8 @@ class _HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
|
|||||||
onUserGesture: () {
|
onUserGesture: () {
|
||||||
if (_followMeMode != FollowMeMode.off) {
|
if (_followMeMode != FollowMeMode.off) {
|
||||||
setState(() => _followMeMode = FollowMeMode.off);
|
setState(() => _followMeMode = FollowMeMode.off);
|
||||||
|
// Save the disabled follow-me mode when user interacts with map
|
||||||
|
MapViewState.saveFollowMeMode(_followMeMode);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -12,9 +12,13 @@ import '../../screens/home_screen.dart' show FollowMeMode;
|
|||||||
class GpsController {
|
class GpsController {
|
||||||
StreamSubscription<Position>? _positionSub;
|
StreamSubscription<Position>? _positionSub;
|
||||||
LatLng? _currentLatLng;
|
LatLng? _currentLatLng;
|
||||||
|
FollowMeMode _currentFollowMeMode = FollowMeMode.off;
|
||||||
|
|
||||||
/// Get the current GPS location (if available)
|
/// Get the current GPS location (if available)
|
||||||
LatLng? get currentLocation => _currentLatLng;
|
LatLng? get currentLocation => _currentLatLng;
|
||||||
|
|
||||||
|
/// Get the current follow-me mode
|
||||||
|
FollowMeMode get currentFollowMeMode => _currentFollowMeMode;
|
||||||
|
|
||||||
/// Initialize GPS location tracking
|
/// Initialize GPS location tracking
|
||||||
Future<void> initializeLocation() async {
|
Future<void> initializeLocation() async {
|
||||||
@@ -44,6 +48,10 @@ class GpsController {
|
|||||||
required FollowMeMode oldMode,
|
required FollowMeMode oldMode,
|
||||||
required AnimatedMapController controller,
|
required AnimatedMapController controller,
|
||||||
}) {
|
}) {
|
||||||
|
// Update the stored follow-me mode
|
||||||
|
_currentFollowMeMode = newMode;
|
||||||
|
debugPrint('[GpsController] Follow-me mode changed: $oldMode → $newMode');
|
||||||
|
|
||||||
// Only act when follow-me is first enabled and we have a current location
|
// Only act when follow-me is first enabled and we have a current location
|
||||||
if (newMode != FollowMeMode.off &&
|
if (newMode != FollowMeMode.off &&
|
||||||
oldMode == FollowMeMode.off &&
|
oldMode == FollowMeMode.off &&
|
||||||
@@ -76,7 +84,6 @@ class GpsController {
|
|||||||
/// Process GPS position updates and handle follow-me animations
|
/// Process GPS position updates and handle follow-me animations
|
||||||
void processPositionUpdate({
|
void processPositionUpdate({
|
||||||
required Position position,
|
required Position position,
|
||||||
required FollowMeMode followMeMode,
|
|
||||||
required AnimatedMapController controller,
|
required AnimatedMapController controller,
|
||||||
required VoidCallback onLocationUpdated,
|
required VoidCallback onLocationUpdated,
|
||||||
}) {
|
}) {
|
||||||
@@ -86,11 +93,12 @@ class GpsController {
|
|||||||
// Notify that location was updated (for setState, etc.)
|
// Notify that location was updated (for setState, etc.)
|
||||||
onLocationUpdated();
|
onLocationUpdated();
|
||||||
|
|
||||||
// Handle follow-me animations if enabled
|
// Handle follow-me animations if enabled - use current stored mode, not parameter
|
||||||
if (followMeMode != FollowMeMode.off) {
|
if (_currentFollowMeMode != FollowMeMode.off) {
|
||||||
|
debugPrint('[GpsController] GPS position update: ${latLng.latitude}, ${latLng.longitude}, follow-me: $_currentFollowMeMode');
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
try {
|
try {
|
||||||
if (followMeMode == FollowMeMode.northUp) {
|
if (_currentFollowMeMode == FollowMeMode.northUp) {
|
||||||
// Follow position only, keep current rotation
|
// Follow position only, keep current rotation
|
||||||
controller.animateTo(
|
controller.animateTo(
|
||||||
dest: latLng,
|
dest: latLng,
|
||||||
@@ -98,7 +106,7 @@ class GpsController {
|
|||||||
duration: kFollowMeAnimationDuration,
|
duration: kFollowMeAnimationDuration,
|
||||||
curve: Curves.easeOut,
|
curve: Curves.easeOut,
|
||||||
);
|
);
|
||||||
} else if (followMeMode == FollowMeMode.rotating) {
|
} else if (_currentFollowMeMode == FollowMeMode.rotating) {
|
||||||
// Follow position and rotation based on heading
|
// Follow position and rotation based on heading
|
||||||
final heading = position.heading;
|
final heading = position.heading;
|
||||||
final speed = position.speed; // Speed in m/s
|
final speed = position.speed; // Speed in m/s
|
||||||
@@ -128,6 +136,9 @@ class GpsController {
|
|||||||
required AnimatedMapController controller,
|
required AnimatedMapController controller,
|
||||||
required VoidCallback onLocationUpdated,
|
required VoidCallback onLocationUpdated,
|
||||||
}) async {
|
}) async {
|
||||||
|
// Store the initial follow-me mode
|
||||||
|
_currentFollowMeMode = followMeMode;
|
||||||
|
|
||||||
final perm = await Geolocator.requestPermission();
|
final perm = await Geolocator.requestPermission();
|
||||||
if (perm == LocationPermission.denied ||
|
if (perm == LocationPermission.denied ||
|
||||||
perm == LocationPermission.deniedForever) {
|
perm == LocationPermission.deniedForever) {
|
||||||
@@ -138,7 +149,6 @@ class GpsController {
|
|||||||
_positionSub = Geolocator.getPositionStream().listen((Position position) {
|
_positionSub = Geolocator.getPositionStream().listen((Position position) {
|
||||||
processPositionUpdate(
|
processPositionUpdate(
|
||||||
position: position,
|
position: position,
|
||||||
followMeMode: followMeMode,
|
|
||||||
controller: controller,
|
controller: controller,
|
||||||
onLocationUpdated: onLocationUpdated,
|
onLocationUpdated: onLocationUpdated,
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user