T12-T14: platform liveness via geolocator; drop flutter_foreground_task
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>
This commit is contained in:
178
lib/main.dart
178
lib/main.dart
@@ -1,122 +1,126 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'src/app/providers.dart';
|
||||
import 'src/recording/recording_engine.dart';
|
||||
|
||||
/// Phase 3 entry point.
|
||||
///
|
||||
/// The UI proper arrives in Phase 4 (T15–T21). This is deliberately a thin harness: it
|
||||
/// exists so the recording pipeline can be exercised on a real device before any screens
|
||||
/// are built, because the pipeline is the part that cannot be validated by unit tests or
|
||||
/// by an emulator.
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
runApp(const ProviderScope(child: RipprApp()));
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
class RipprApp extends StatelessWidget {
|
||||
const RipprApp({super.key});
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
title: 'Rippr',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
// This is the theme of your application.
|
||||
//
|
||||
// TRY THIS: Try running your application with "flutter run". You'll see
|
||||
// the application has a purple toolbar. Then, without quitting the app,
|
||||
// try changing the seedColor in the colorScheme below to Colors.green
|
||||
// and then invoke "hot reload" (save your changes or press the "hot
|
||||
// reload" button in a Flutter-supported IDE, or press "r" if you used
|
||||
// the command line to start the app).
|
||||
//
|
||||
// Notice that the counter didn't reset back to zero; the application
|
||||
// state is not lost during the reload. To reset the state, use hot
|
||||
// restart instead.
|
||||
//
|
||||
// This works for code too, not just values: Most code changes can be
|
||||
// tested with just a hot reload.
|
||||
colorScheme: .fromSeed(seedColor: Colors.deepPurple),
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: const Color(0xFFFF6B1A), // safety orange, matching the icon
|
||||
brightness: Brightness.dark,
|
||||
),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
home: const _RecorderHarness(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title});
|
||||
|
||||
// This widget is the home page of your application. It is stateful, meaning
|
||||
// that it has a State object (defined below) that contains fields that affect
|
||||
// how it looks.
|
||||
|
||||
// This class is the configuration for the state. It holds the values (in this
|
||||
// case the title) provided by the parent (in this case the App widget) and
|
||||
// used by the build method of the State. Fields in a Widget subclass are
|
||||
// always marked "final".
|
||||
|
||||
final String title;
|
||||
class _RecorderHarness extends ConsumerStatefulWidget {
|
||||
const _RecorderHarness();
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
ConsumerState<_RecorderHarness> createState() => _RecorderHarnessState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
class _RecorderHarnessState extends ConsumerState<_RecorderHarness> {
|
||||
String? _error;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
// This call to setState tells the Flutter framework that something has
|
||||
// changed in this State, which causes it to rerun the build method below
|
||||
// so that the display can reflect the updated values. If we changed
|
||||
// _counter without calling setState(), then the build method would not be
|
||||
// called again, and so nothing would appear to happen.
|
||||
_counter++;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Re-attach to a ride that was in progress when the process died. Must happen before
|
||||
// any user interaction, and the database is the only thing that knows.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await ref.read(recordingEngineProvider).restoreAfterProcessDeath();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _run(Future<void> Function() action) async {
|
||||
try {
|
||||
await action();
|
||||
if (mounted) setState(() => _error = null);
|
||||
} catch (e) {
|
||||
if (mounted) setState(() => _error = '$e');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// This method is rerun every time setState is called, for instance as done
|
||||
// by the _incrementCounter method above.
|
||||
//
|
||||
// The Flutter framework has been optimized to make rerunning build methods
|
||||
// fast, so that you can just rebuild anything that needs updating rather
|
||||
// than having to individually change instances of widgets.
|
||||
final engine = ref.watch(recordingEngineProvider);
|
||||
final state = ref.watch(recorderStateProvider).valueOrNull ?? engine.state;
|
||||
final trip = ref.watch(activeTripProvider).valueOrNull;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
// TRY THIS: Try changing the color here to a specific color (to
|
||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
||||
// change color while the other colors stay the same.
|
||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
||||
// Here we take the value from the MyHomePage object that was created by
|
||||
// the App.build method, and use it to set our appbar title.
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Center(
|
||||
// Center is a layout widget. It takes a single child and positions it
|
||||
// in the middle of the parent.
|
||||
appBar: AppBar(title: const Text('Rippr — recorder harness')),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
// Column is also a layout widget. It takes a list of children and
|
||||
// arranges them vertically. By default, it sizes itself to fit its
|
||||
// children horizontally, and tries to be as tall as its parent.
|
||||
//
|
||||
// Column has various properties to control how it sizes itself and
|
||||
// how it positions its children. Here we use mainAxisAlignment to
|
||||
// center the children vertically; the main axis here is the vertical
|
||||
// axis because Columns are vertical (the cross axis would be
|
||||
// horizontal).
|
||||
//
|
||||
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
|
||||
// action in the IDE, or press "p" in the console), to see the
|
||||
// wireframe for each widget.
|
||||
mainAxisAlignment: .center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const Text('You have pushed the button this many times:'),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
Text('State: ${state.name}',
|
||||
style: Theme.of(context).textTheme.headlineSmall),
|
||||
const SizedBox(height: 12),
|
||||
if (trip != null) ...[
|
||||
Text('Trip ${trip.id} · ${trip.pointCount} points'),
|
||||
Text('${trip.distanceM.toStringAsFixed(1)} m'),
|
||||
Text('max ${trip.maxSpeedKmh.toStringAsFixed(1)} km/h'),
|
||||
] else
|
||||
const Text('No active ride'),
|
||||
if (_error != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text(_error!, style: const TextStyle(color: Colors.redAccent)),
|
||||
],
|
||||
const Spacer(),
|
||||
// 72dp targets, matching the native app's glove-sized controls.
|
||||
SizedBox(
|
||||
height: 72,
|
||||
child: FilledButton(
|
||||
onPressed: () => _run(engine.start),
|
||||
child: Text(state == RecorderState.paused ? 'RESUME' : 'START'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
height: 72,
|
||||
child: OutlinedButton(
|
||||
onPressed: state == RecorderState.recording
|
||||
? () => _run(engine.pause)
|
||||
: null,
|
||||
child: const Text('PAUSE'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
height: 72,
|
||||
child: OutlinedButton(
|
||||
onPressed: state == RecorderState.idle
|
||||
? null
|
||||
: () => _run(() async => engine.stop()),
|
||||
child: const Text('STOP'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user