V3-02 + V3-03: settings screen, and metric/imperial units
Built together because V3-02's settings screen needed something real for V3-03's units to control -- executed in reverse of the ticket numbering, but both tickets are independently complete. V3-03: UnitSystem (metric/imperial) lives in domain/models.dart alongside Activity, defaulting from Platform.localeName on first launch. Storage stays SI everywhere -- conversion happens only in ui/format.dart, at the last possible moment, which is now documented as the file's central invariant. Threaded through all three screens plus the speed histogram's bucket labels, which relabel for display without changing how speedHistogram itself bins. Export was deliberately left untouched: gpx()/geoJson() take no UnitSystem parameter at all, a stronger guarantee than validating one would be. V3-02: SettingsScreen reachable from the record screen. Map render toggle (nothing previously exposed mapEnabledProvider to the user, despite it existing since T15 -- there was nothing to "move off trip detail" as drafted), unit selector, upload endpoint with http(s) validation, a copyable device id, and a licences page via Flutter's built-in showLicensePage. Skipped package_info_plus (static version string instead) and a privacy-policy link (none published yet) as disproportionate to an S-sized ticket. Neither ticket needed the ConfigNotifier the implementation notes proposed: unitSystemProvider reuses the exact StateProvider-seeded-from-Config pattern mapEnabledProvider already established, since Config mutates its own backing SharedPreferences in place and re-assigning the same instance would never notify a watcher anyway. A real locale-dependent flake was caught, not just anticipated: a test asserting a fresh Config defaults to metric failed, because this machine's own locale resolves to a region in the imperial set. Fixed by seeding an explicit value before asserting, and config_test.dart's locale test was written from the start to only prove the fallback path doesn't throw, not to assert which value it returns. 221 tests (211 -> 221): 13 format_test, 9 config_test, 9 settings_screen_test, 1 confirming the record screen's settings button is genuinely wired. Analyze clean. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -109,6 +109,7 @@ class TripDetailScreen extends ConsumerWidget {
|
||||
),
|
||||
AsyncValue(hasValue: true, value: final d?) => _Body(
|
||||
detail: d,
|
||||
units: ref.watch(unitSystemProvider),
|
||||
onEditActivity: () => _editActivity(context, ref, d.trip),
|
||||
),
|
||||
AsyncValue(hasError: true, :final error) => EmptyState(
|
||||
@@ -219,14 +220,23 @@ class TripDetailScreen extends ConsumerWidget {
|
||||
}
|
||||
|
||||
class _Body extends StatelessWidget {
|
||||
const _Body({required this.detail, required this.onEditActivity});
|
||||
const _Body({
|
||||
required this.detail,
|
||||
required this.units,
|
||||
required this.onEditActivity,
|
||||
});
|
||||
|
||||
final TripDetail detail;
|
||||
final UnitSystem units;
|
||||
final VoidCallback onEditActivity;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = detail.summary;
|
||||
final (distanceValue, distanceUnit) = formatDistanceParts(
|
||||
s.distanceM,
|
||||
unit: units,
|
||||
);
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
@@ -234,8 +244,8 @@ class _Body extends StatelessWidget {
|
||||
child: BigStat(
|
||||
key: const Key('distance'),
|
||||
label: 'DISTANCE',
|
||||
value: (s.distanceM / 1000).toStringAsFixed(1),
|
||||
unit: 'km',
|
||||
value: distanceValue,
|
||||
unit: distanceUnit,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@@ -266,18 +276,21 @@ class _Body extends StatelessWidget {
|
||||
label: 'Stopped',
|
||||
value: formatDuration(s.stoppedMillis),
|
||||
),
|
||||
StatRow(label: 'Max speed', value: formatSpeed(s.maxSpeedKmh)),
|
||||
StatRow(
|
||||
label: 'Max speed',
|
||||
value: formatSpeed(s.maxSpeedKmh, unit: units),
|
||||
),
|
||||
StatRow(
|
||||
label: 'Avg moving speed',
|
||||
value: formatSpeed(s.avgMovingSpeedKmh),
|
||||
value: formatSpeed(s.avgMovingSpeedKmh, unit: units),
|
||||
),
|
||||
StatRow(
|
||||
label: 'Elevation gain',
|
||||
value: formatElevation(s.elevationGainM),
|
||||
value: formatElevation(s.elevationGainM, unit: units),
|
||||
),
|
||||
StatRow(
|
||||
label: 'Elevation loss',
|
||||
value: formatElevation(s.elevationLossM),
|
||||
value: formatElevation(s.elevationLossM, unit: units),
|
||||
),
|
||||
StatRow(label: 'Points', value: '${s.pointCount}'),
|
||||
StatRow(label: 'Segments', value: '${detail.segments.length}'),
|
||||
@@ -287,7 +300,7 @@ class _Body extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
_SectionTitle('Speed distribution'),
|
||||
_Histogram(buckets: detail.histogram),
|
||||
_Histogram(buckets: detail.histogram, units: units),
|
||||
const SizedBox(height: 24),
|
||||
_SectionTitle('Elevation profile'),
|
||||
_ElevationChart(samples: detail.profile),
|
||||
@@ -351,9 +364,10 @@ class _SectionTitle extends StatelessWidget {
|
||||
/// Degrades to a message rather than an empty box: a ride of one point has no intervals
|
||||
/// to measure, and an unexplained blank looks like a bug.
|
||||
class _Histogram extends StatelessWidget {
|
||||
const _Histogram({required this.buckets});
|
||||
const _Histogram({required this.buckets, required this.units});
|
||||
|
||||
final List<SpeedBucket> buckets;
|
||||
final UnitSystem units;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -375,7 +389,7 @@ class _Histogram extends StatelessWidget {
|
||||
SizedBox(
|
||||
width: 64,
|
||||
child: Text(
|
||||
b.label,
|
||||
formatSpeedRangeLabel(b.fromKmh, b.toKmh, unit: units),
|
||||
style: TextStyle(fontSize: 12, color: colors.outline),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user