feat(location): add manual frequency option and optimize position loading

This commit is contained in:
2026-04-26 05:12:10 +02:00
parent cf2dbbeb63
commit 7251349e1d
6 changed files with 26 additions and 13 deletions

View File

@@ -25,15 +25,22 @@ class LocationController extends _$LocationController {
final device = ref.watch(selectedDeviceProvider).value;
if (device == null) return const LocationState();
final results = await Future.wait([
repo.getGeofences(deviceId: device.id),
repo.getFrequentPlaces(deviceId: device.id),
]);
await Future<void>.delayed(const Duration(milliseconds: 300));
if (!ref.mounted) return const LocationState();
return LocationState(
geofences: results[0] as List<GeofenceEntity>,
frequentPlaces: results[1] as List<FrequentPlaceEntity>,
);
try {
final results = await Future.wait([
repo.getGeofences(deviceId: device.id),
repo.getFrequentPlaces(deviceId: device.id),
]);
return LocationState(
geofences: results[0] as List<GeofenceEntity>,
frequentPlaces: results[1] as List<FrequentPlaceEntity>,
);
} catch (_) {
return const LocationState();
}
}
Future<bool> createGeofence({

View File

@@ -645,7 +645,7 @@ class _LocationMapState extends ConsumerState<LocationMap>
currentFrequency:
ref.watch(selectedDeviceProvider).value?.settings.frequency ?? 60,
options: widget.selectedDevice!.capabilities!.location!.options
.where((o) => o > 0)
.where((o) => o > 0 || o == -1)
.toList(),
onChanged: _updateFrequency,
),

View File

@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:location/src/features/location/presentation/providers/location_map_controller.dart';
import 'package:sf_localizations/sf_localizations.dart';
import 'package:utils/utils.dart';
import 'map_action_button.dart';
@@ -136,8 +137,9 @@ class FrequencySelector extends ConsumerWidget {
vm.collapseFrequency();
},
child: Container(
width: 40,
constraints: const BoxConstraints(minWidth: 40),
height: 32,
padding: const EdgeInsets.symmetric(horizontal: 6),
margin: const EdgeInsets.symmetric(vertical: 2),
decoration: BoxDecoration(
color: selected
@@ -147,9 +149,11 @@ class FrequencySelector extends ConsumerWidget {
),
child: Center(
child: Text(
formatSecondsCompact(opt),
opt == -1
? context.translate(I18n.locationFrequencyManual)
: formatSecondsCompact(opt),
style: TextStyle(
fontSize: 12,
fontSize: opt == -1 ? 10 : 12,
fontWeight: FontWeight.w600,
color: selected
? Theme.of(context).colorScheme.surface

View File

@@ -14,6 +14,7 @@ class LegacyDeviceRemoteDatasourceImpl implements LegacyDeviceRemoteDatasource {
try {
final response = await _repository.get<Map<String, dynamic>>(
'/devices/identificator/$deviceId/positions',
queryParameters: <String, dynamic>{'pageSize': 5},
);
final data = response.data;

View File

@@ -21,7 +21,7 @@ class LegacyDeviceViewModel extends AsyncNotifier<LegacyDeviceViewState> {
final devices = await ref.watch(legacyDevicesProvider.future);
if (devices.isEmpty) return const LegacyDeviceViewState();
final selected = await ref.watch(selectedDeviceProvider.future);
final selected = await ref.read(selectedDeviceProvider.future);
final (latestPositions, hadError) = await _fetchPositions(devices);
final selectedPosition = selected != null

View File

@@ -1,4 +1,5 @@
String formatSecondsCompact(int seconds) {
if (seconds < 0) return '';
if (seconds >= 3600) return '${seconds ~/ 3600}h';
if (seconds >= 60) return '${seconds ~/ 60}m';
return '${seconds}s';