29 lines
1.0 KiB
Dart
29 lines
1.0 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:geolocator/geolocator.dart';
|
|
|
|
/// Provides the device current position on demand. Tests may override this
|
|
/// provider to inject a fake Position.
|
|
final currentPositionProvider = FutureProvider.autoDispose<Position>((
|
|
ref,
|
|
) async {
|
|
// Mirror the runtime usage in the app: ask geolocator for the current
|
|
// position with high accuracy. Caller (UI) should handle permission
|
|
// flows / errors.
|
|
final position = await Geolocator.getCurrentPosition(
|
|
locationSettings: const LocationSettings(accuracy: LocationAccuracy.high),
|
|
);
|
|
return position;
|
|
});
|
|
|
|
/// Stream of device positions for live tracking. Tests can override this
|
|
/// provider to inject a fake stream.
|
|
final currentPositionStreamProvider = StreamProvider.autoDispose<Position>((
|
|
ref,
|
|
) {
|
|
const settings = LocationSettings(
|
|
accuracy: LocationAccuracy.high,
|
|
distanceFilter: 5, // small filter for responsive UI in tests/dev
|
|
);
|
|
return Geolocator.getPositionStream(locationSettings: settings);
|
|
});
|