Distance Display Formatting#
The Distance Resolution preference controls whether workout distances are shown in small units (meters/yards β "high resolution") or large units (km/miles β "low resolution") across the app UI. It is a pure display setting with no effect on the underlying distance values stored in the database.
Preference Definition#
Defined in lib/preferences/distance_resolution.dart:
| Constant | Value |
|---|---|
distanceResolution | "Distance Resolution High/Low" (display label) |
distanceResolutionTag | "distance_resolution" (pref key) |
distanceResolutionDefault | false (low resolution β km/mi β by default) |
distanceResolutionDescription | "On: high resolution - m or yd, Off: low resolution - km or mi." |
The default is false (low resolution), meaning users see km/mi unless they explicitly toggle the setting on .
Settings UI#
The preference is exposed as a PrefCheckbox in the User Experience Preferences screen (lib/ui/preferences/user_experience_preferences.dart), directly below the metric/imperial (SI) unit toggle.
It is initialized at startup in lib/utils/init_preferences.dart as part of the getPrefDefaults() map.
Display Logic#
Three functions in lib/utils/display.dart implement the formatting. All accept a bool si (metric vs. imperial) and bool highRes (distance resolution preference):
distanceString(distance, si, highRes)β formats the numeric value:si + highResβ integer meters (toStringAsFixed(0))si + !highResβ km to 2 decimal places (distance / 1000)!si + highResβ yards (distance * m2yard)!si + !highResβ miles (distance * m2mile)
distanceUnit(si, highRes)β returns the unit label ("m","km","yd", or"mi").distanceByUnit(distance, si, highRes, {autoRes})β combines value + unit into a single string. WhenautoRes: true, it auto-selects resolution based on magnitude: switches to high-res below 999 m (SI) or ~914 m (imperial, i.e., 1000 yd), overriding the user preference for small lap distances.
Screens That Consume highRes#
Each screen reads the preference in initState() and passes it as _highRes to the display functions. No live observation is wired β the value is captured once on screen load.
| Screen | File | Usage |
|---|---|---|
| Activity list | lib/ui/activities.dart | distanceString(_si, _highRes) + distanceUnit in list rows |
| Activity details | lib/ui/details/activity_details.dart | distanceString + distanceUnit in the stats header |
| Recording screen | lib/ui/recording/recording_screen.dart | live measurement rows + leaderboard lap info via distanceByUnit(..., autoRes: true) |
| Sport leaderboard | lib/ui/leaderboards/sport_leaderboard.dart | distanceStringWithUnit(_si, _highRes) in workout summaries |
| Device leaderboard | lib/ui/leaderboards/device_leaderboard.dart | distanceStringWithUnit(_si, _highRes) in workout summaries |
Key Design Notes#
- Orthogonal to SI/imperial. The
siflag (fromunitSystemTag) controls which unit system (metric vs. imperial);highRescontrols which magnitude within that system. Both flags are always passed together. - No recalculation. The raw distance value (stored in meters) is never changed β only the formatted string varies.
autoResoverride. The recording screen usesautoRes: truefor lap/leaderboard delta distances, so very short segments automatically show in m/yd regardless of the user setting .- Default is low-res (km/mi). Engineers adding new distance display calls should default to
distanceResolutionDefault = falseand readdistanceResolutionTagfrom the preference service for consistency.