Distance Prefill Service
Component Detail
Description
Manages reading and writing the per-user last-used distance so that recurring routes require minimal re-entry. Persists values in local device storage and updates the stored default after each successful submission.
distance-prefill-service
Summaries
The Distance Prefill Service meaningfully reduces the time employees spend submitting repeat mileage claims — a friction point that, if left unaddressed, drives lower adoption of the expense platform and more paper-based workarounds. By remembering the last distance entered for each user and pre-populating the form on the next visit, the service rewards employees who commute regular routes, reducing data entry to a single confirmation tap for the majority of claims. This translates directly into higher submission rates, faster reimbursement cycles, and a demonstrably better employee experience that reinforces platform adoption across the organisation.
Low development complexity with a single dependency on the local device cache layer. The primary delivery consideration is defining the cache key strategy (user-scoped) and the clear-on-logout requirement, both of which must be coordinated with the authentication team to ensure the logout event is reliably intercepted. Testing must cover: first-time users (null return), returning users (correct prefill), cache clearing on logout, and behaviour after a failed submission (should not update cache). The component is a mobile-only concern and has no backend coordination, which simplifies deployment.
It can be developed in parallel with other form components as long as the local-distance-cache interface is agreed upfront.
DistancePrefillService wraps a LocalDistanceCache dependency (which should abstract SharedPreferences or equivalent local storage). getLastUsedDistance(userId) → Future
Cache keys should be namespaced (e.g., distance_prefill_{userId}) to prevent cross-user data leakage on shared devices. All three methods return Futures even though the underlying storage may be synchronous, preserving the option to swap in a remote-backed cache later.
Responsibilities
- Read the cached last-used distance for the current user
- Write the new distance after a successful claim submission
- Clear the cached value on user logout
- Return null when no prior entry exists, letting the field show an empty placeholder
Interfaces
getLastUsedDistance(String userId) → Future<double?>
saveLastUsedDistance(String userId, double distanceKm) → Future<void>
clearCache(String userId) → Future<void>