geolocator_android's ForegroundNotificationConfig raises a service with foregroundServiceType=location and holds a wake lock for as long as the position stream is subscribed, and the plugin declares that service in its own manifest. That covers everything the native TrackingService used a foreground service and a PARTIAL_WAKE_LOCK for, so flutter_foreground_task is gone -- and with it both deprecation warnings that were recorded under T01. Known parity gap for T27: geolocator's notification cannot carry actions, so the native Pause/Resume buttons in the shade are not reproduced. iOS: UIBackgroundModes plus allowBackgroundLocationUpdates keep the isolate and the writer timer alive while updates flow. Two settings matter more than they look -- pauseLocationUpdatesAutomatically is false because CoreLocation does not reliably restart, and activityType is otherNavigation rather than automotiveNavigation, which would snap fixes to the road network and silently falsify the recorded path. Usage strings are specific, not generic. Android deliberately does not request ACCESS_BACKGROUND_LOCATION: a foreground service with a visible notification is exactly the supported case, and asking would trigger the harder "Allow all the time" flow for no benefit. T14 process-death resume is implemented and called at startup, covered by four tests including the 111 km crash-gap guard. Verified by building both platforms and launching on the iOS simulator: Drift opened, Riverpod resolved, restore found no active trip, controls correct. lib/main.dart is a harness so the pipeline can be exercised on hardware before Phase 4 builds screens; T15 replaces it. Phase 3 done: 145 tests passing, analyze clean. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
68 lines
2.3 KiB
Dart
68 lines
2.3 KiB
Dart
/// Composition root.
|
|
///
|
|
/// The one place that decides which concrete implementations the app runs with. Tests
|
|
/// override these rather than reaching for singletons — the mistake the native app made
|
|
/// with `AppDatabase.getDatabase()` and `TripRepository.get()`, which is how an
|
|
/// instrumented test once wiped a real device's rides.
|
|
library;
|
|
|
|
import 'package:drift/drift.dart' show driftRuntimeOptions;
|
|
import 'package:drift_flutter/drift_flutter.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../data/database.dart';
|
|
import '../data/trip_repository.dart';
|
|
import '../domain/models.dart';
|
|
import '../recording/geolocator_location_source.dart';
|
|
import '../recording/location_source.dart';
|
|
import '../recording/recording_engine.dart';
|
|
|
|
/// The Drift database, opened against app-private storage.
|
|
///
|
|
/// Overridden in tests with an in-memory instance.
|
|
final databaseProvider = Provider<AppDatabase>((ref) {
|
|
driftRuntimeOptions.dontWarnAboutMultipleDatabases = true;
|
|
final db = AppDatabase(driftDatabase(name: 'rippr_db'));
|
|
ref.onDispose(db.close);
|
|
return db;
|
|
});
|
|
|
|
final tripRepositoryProvider = Provider<TripRepository>(
|
|
(ref) => TripRepository(ref.watch(databaseProvider)),
|
|
);
|
|
|
|
/// Overridden in tests with [FakeLocationSource].
|
|
final locationSourceProvider = Provider<LocationSource>((ref) {
|
|
final source = GeolocatorLocationSource();
|
|
ref.onDispose(source.dispose);
|
|
return source;
|
|
});
|
|
|
|
final recordingEngineProvider = Provider<RecordingEngine>((ref) {
|
|
final engine = RecordingEngine(
|
|
repository: ref.watch(tripRepositoryProvider),
|
|
locationSource: ref.watch(locationSourceProvider),
|
|
);
|
|
ref.onDispose(engine.dispose);
|
|
return engine;
|
|
});
|
|
|
|
// --- Reactive state ---------------------------------------------------------
|
|
|
|
/// The in-progress ride, straight from the database.
|
|
///
|
|
/// Recording state is derived, never held as a flag — that is what makes it survive
|
|
/// process death.
|
|
final activeTripProvider = StreamProvider<Trip?>(
|
|
(ref) => ref.watch(tripRepositoryProvider).watchActiveTrip(),
|
|
);
|
|
|
|
final completedTripsProvider = StreamProvider<List<Trip>>(
|
|
(ref) => ref.watch(tripRepositoryProvider).watchCompletedTrips(),
|
|
);
|
|
|
|
final recorderStateProvider = StreamProvider<RecorderState>((ref) {
|
|
final engine = ref.watch(recordingEngineProvider);
|
|
return engine.stateStream;
|
|
});
|