AI work/On-device summary
On-device summary
Flutter, Riverpod, ML Kit GenAI, one Kotlin platform channel, and a Gemini free-tier fallback that stays off until you turn it on.
- 97 tests, all green
- 15.5 s tap to card on an emulator
- Nothing to run: no spend
A note in, a line and a category out
Paste a note, get a one-line summary and a category (work, personal, idea or other). The top of the screen says where that summary ran: on the phone, in the cloud, or nowhere.
- Flutter
- Dart
- Riverpod
- ML Kit GenAI
- Gemini Nano
- Kotlin channel
- Gemini API
Android, minSdk 26, target 36 · English only · Ghon4/on-device-summary
What you get, before the architecture
The people this is for paste notes they would not post publicly: a standup update, a customer email, a paragraph of a report. They want two things out of it, fast, without thinking about where it was processed.
On a phone that can run Google's on-device model, the text never leaves the device. No account, no key, no network, and it still works in airplane mode. On a phone that cannot, the app says so and does nothing until you turn the cloud fallback on yourself. Either way the screen tells you which of those happened, in one line, before you paste anything.
The private path is the default. The network path is a switch you flip. The switch starts off every time the app opens.
The problem
Three constraints, and any two of them are easy to satisfy together.
- Most phones cannot run the model. Gemini Nano arrives through AICore on recent flagship Android phones, not on the phone most people carry.
- The text is the sensitive part. Sending it to a hosted model is a decision the person pasting it should make, not one the app makes for them.
- A silent fallback is a lie. If the app quietly sends the note when the local model is missing, the privacy story it tells on its first screen is false.
The obvious build, one call to a hosted model, fails all three. The obvious fix, on-device only, fails the first one. So the app is built around a single honest question, asked again on every run: where can this summary actually happen right now?
The design
The answer comes from two facts: whether the phone reports the on-device model as available, and whether the cloud switch is on. Everything else follows from that table.
| Model ready | Cloud switch | Path | What the screen says |
|---|---|---|---|
| Yes | Off | On-device | On this phone. The text never leaves it. |
| Yes | On | On-device | On this phone. The switch does not override a working phone. |
| No | On | Cloud fallback | The summary is sent to Google's Gemini API. |
| No | Off | Nothing runs | Not available on this device. Nothing is sent. |
The path is chosen per run, not at startup
A model download can finish while the app is open, and the switch can flip between two taps. Choosing once at launch would be stale within a minute of use, so the controller asks the capability service on every run.
The cloud object cannot exist while the switch is off
The cloud summarizer is a Riverpod provider that throws when the switch is off. The controller only reads it on the cloud path, so the private path has no object in reach that is capable of opening a socket. That turns "nothing is sent on the on-device path" from a promise into something the structure enforces, and something a test can assert.
Tests never load a model or open a socket
The platform channel sits behind a DeviceCapability interface and the HTTP call is a function type, so both boundaries are fake in tests. The real Kotlin channel and the real dart:io client are only wired in the running app.
Nothing is stored
The switch, the note and the result are in memory and die with the process. A cold start is always the private, off state, and there is no history to leak or migrate.
Eval
97 tests across 9 files, all green, against 1,571 lines of app code. The suite is bigger than the app because the interesting behaviour is at the boundaries: the platform channel, the HTTP call, and the decision between them.
offline_path_test.dartasserts the cloud summarizer cannot be built while the switch is off, that a run with the switch off makes zero requests, and that a run where on-device works makes zero requests even with the switch on.- Widget tests drive the screen through its states: idle, download card with progress, loading, the retry note, result, error with Retry, and the unavailable card.
- The summarizer tests cover the parse path that matters in practice: a category outside the fixed set becomes
other, a code fence around the JSON is tolerated, and an empty summary is an error rather than a blank card.
The run, and the failure in it
The emulator has no AICore, which is exactly the case the cloud path exists for. With the switch on, one tap produced a summary and a work chip in 15.5 seconds from tap to card, including the UI-dump polling I used to confirm the card was on screen.
The first live run before that did not produce anything. It came back with "The cloud service took too long." The request had been overloaded (HTTP 503), the app retried it once as designed, and that retry sat inside a 45 second window: 15 seconds to connect, 45 for the response and 45 for the body. An overloaded model looked like a hang.
The fix was not a bigger timer. I measured the flash models on the same key: 3.8-flash answered correctly in 39.4 seconds, 3.6-flash and 3.5-flash answered in 0.9 seconds, and 2.5-flash returned 404. Pinning 3.6-flash (f761027) put the whole tap to card inside 15.5 seconds. The result card screenshot from that run is committed with the docs (e7e1698).
A 39.4 second answer against a 45 second timeout is not a working path. It is a path that works until the day it does not.
Cost
There is nothing to run. On-device inference is part of the operating system, the cloud path is on the Gemini API free tier, and there is no server, database, account or hosting bill behind any of it.
The free tier is not free in every sense, and the app is built around that:
- A failed call still spends quota, and the single 503 retry spends two calls. That is why there is exactly one retry, and no background polling of the model or the network.
- When the limit is hit the app says so: the 429 path shows "The free tier limit was reached. Try again in a minute." rather than an error nobody can act on.
- The API key is compiled into the build. That is fine for a personal demo and wrong for a product, because anyone can extract it from a shipped APK. A real version puts a small server in front and keeps the key there. The README says this in the same words.
What I would change
- A 20 second ceiling on the cloud call, not 45. The long window is what turned an overload into a hang. A short one fails while the person is still looking at the screen and offers the retry they can act on.
- Choose the model by measured latency, in the repo. Taking the newest model name cost a live run and a 39.4 second surprise. The numbers that settled it belong next to the constant, not in a message.
- Retry on the next tap, not inside the same one. One tap that waits twice as long is worse than one tap that says "overloaded, try again", because the second one is a decision the person makes.
- Test the on-device path on a phone with AICore. It is covered by fakes and by the offline test, and it has never run on hardware I could hold. That is the missing evidence in this write-up, and it is the first thing I would get.
- Rehearse the demo against the tooling. On the take, the emulator's clipboard paste never landed, typing the note ate 26 seconds, and
screenrecordrefused the 1280 width and wrote 720x1280. None of it changed the app; all of it changed the clip.
Demo
What this is not
A product. It has no account, no storage, no history, and it is English only. The on-device path runs only on phones that have Gemini Nano, which today means recent flagships. It is a small, complete piece of engineering built to answer one question honestly, and it is the first of three projects on this site.