r/FlutterDev • u/eroxy • Aug 26 '26
Example Lessons from shipping a geofencing time tracker in Flutter: platform channels, OEM battery killers, and a no-backend constraint
I shipped a geofencing time tracker in Flutter (auto clock-in/out at your workplace) and collected a few scars along the way that might save someone else time.
The first one: I tried the pub.dev geofencing packages and none of them reliably delivered events after the app got killed. Ended up writing my own thin Kotlin plugin around the Google Geofencing API - MethodChannel for registering zones, EventChannel for the ENTER/EXIT stream, and a system-level BroadcastReceiver so events arrive even when the Flutter side is long dead. Annoying to write, but it's been the most stable part of the app since.
Second scar, the expensive one: Samsung and Xiaomi still eat geofence events sometimes, so there's a WorkManager task every 15 minutes doing a plain Haversine distance check as a safety net. What nobody tells you is that a position request in a background isolate can just hang forever, and once that happens WorkManager considers the unique task "already enqueued" and never runs it again. Your fallback dies silently and permanently. Everything is triple-bounded now: platform timeLimit, a Dart-side timeout, and a hard cap on the whole task.
Third: GPS drift at the zone edge gave me check-in/check-out ping-pong when someone sits near the boundary. Exit radius is now 1.2x the enter radius plus a 5-minute debounce, and the two detection layers share a 20-minute dedup window so they stop racing each other into double notifications.
Rest of the stack is unspectacular: Riverpod (classic providers, no codegen), Isar for storage, no backend at all. The no-backend part had one non-obvious consequence: since data only exists on the user's device, a data-loss bug is unrecoverable, so the integration tests run on an emulator before every push. Codebase is ~31k lines, about a third tests.
The result is free with no ads/IAPs if you want to see how it behaves: https://play.google.com/store/apps/details?id=com.timetracker.workflow
Happy to answer anything about the plugin or the fallback design. And if someone has a real answer to OEM battery killers beyond "diagnostics screen + let the user fix it manually", I'd love to hear it.
2
u/dakevs Aug 27 '26
Thanks for sharing. This is an interesting post ! Like that you shared the thought process on it
3
u/nikhil_akki Aug 27 '26
this is such a nasty failure mode, that's the kind of bug you only discover because a user complained months later.
on the oem battery killer question, the only thing that's ever actually moved the needle for us beyond a generic diagnostics screen is detecting the manufacturer at runtime and showing manufacturer specific instructions, since samsung's battery settings path looks nothing like xiaomi's.
we also started logging whenever the app got killed while backgrounded just so we could see how often it was happening instead of guessing. still feels like duct tape more than a real fix, this whole part of android is rough.
2
u/FlimsyMacaroon76 Aug 27 '26
The no backend bit is the one i'd underline. it's great until you ship a bug in whatever you persist locally, then there's no remote config and no way to touch anyone's data, every fix has to be a client side migration that runs once and is still safe on someone who skipped three versions. i gate all of mine behind a schema version int in prefs now, learned that after nearly shipping something that would have wiped progress for existing users.
2
u/Kaylaya Aug 27 '26
Amazing engineering work here.
Any chance you are planning to publish a pub package for this ? May be by stripping off all the UI and tracking and just the barebones geofencing triggers with storage ?
1
u/aszepeshazi Aug 26 '26
If there is no backend at all, how is clock in clock out measured? Do the employees have to show their numbers at the end of the month on their devices?
2
u/_everpine Sep 05 '26
I ran into this while working on a medical reminder app, where timing actually matters. WorkManager is fine for background sync, but I wouldn’t trust it for something that must fire at an exact time. For time-critical stuff, use
AlarmManagerwithsetExactAndAllowWhileIdle()+RTC_WAKEUP, and restore alarms after reboot viaBOOT_COMPLETED. Battery optimization exemptions only cover Android’s own Doze. Huawei/Xiaomi have their own app killers and autostart rules on top of that. On our Huawei Nova 5T, background behavior still breaks after reboot unless “App launch -> Manage manually” is enabled by hand. A foreground service during the critical window helps, but there’s no universal fix. In practice you’re dealing with a bunch of vendor-specific process-killing policies.