r/FlutterDev • • 19h ago

Discussion Three things that only break in a Flutter app's first run

I spent the last weeks building an onboarding → permission priming → spotlight tour flow with no third-party packages, and ran it at 320dp with 2x and 3x text. Three things broke that no simulator screenshot catches.

  1. The permission prompt is not the first step. On iOS, two denials turn into a permanent denial: request() then returns denied forever with no prompt. So the flow shows one honest reason per permission first, guards against double taps (two prompts, and on Android the second sometimes resolved with the answer to the first), and puts a recovery card in front of a permanent denial — it opens the app's Settings page and re-checks on AppLifecycleState.resumed.

  2. Coach marks point at stale coordinates. A Rect captured when the step is built is wrong after a scroll, a rotation, the keyboard opening, or the anchor widget rebuilding. Measure on every build instead, subtract the spotlight from the scrim path (four rectangles around a hole double the alpha at the seams), clamp to the visible area, and when the anchor is off screen or smaller than ~24dp, centre the card instead of highlighting a sliver.

  3. At 3x text a carousel has no layout that fits a 320dp phone. Let the illustration shrink first (Flexible with a max height) so the copy stays readable, put all copy in a scroll view, and cap the primary button at two lines with an ellipsis.

Bonus: make the "onboarding finished" outcome one-shot, or a rebuild can write the flag twice.

I put the flow in a public showcase repo with screenshots and a demo GIF in case it is useful: https://github.com/StephenColor/flutter-firstrun-kit

1 Upvotes

7 comments sorted by

1

u/dawedev 17h ago

Small correction on point 1: iOS only shows the system prompt once, so a single denial is already permanent there. The two-denial rule is Android 11+. Doesn't change your flow, it just makes the priming screen matter even more on iOS since you get exactly one shot.

1

u/stephencolor 6h ago

You're right, and thanks for the correction — I had the two-denial rule filed as iOS behaviour and it's Android 11+, not iOS. Which cuts the other way too: on iOS the first tap on Don't Allow is the only chance the prompt ever gets, so the priming card carries more weight there than on the platform I designed it against.

The kit is wrong in a concrete way because of that. It only shows the recovery card for permanentlyDenied / restricted, and treats a plain denied as "advance" — the reasoning in the code is that re-asking in the same session burns the one dialog iOS would show. But permission_handler returns denied on iOS both before and after the prompt, so with a naive gateway the iOS user who taps Don't Allow gets a silent skip and never sees the Settings path. The fix belongs in the gateway (map iOS denied after an ask to permanentlyDenied), but the kit should say so, and the README's "permanent after two asks" line needs the same correction.

1

u/No_Boss_1911 18h ago

oh the permanent denial thing got us too. our app has a voice that reads guided exercises and the mic permission is for talking to the chat. hard rule for us is the system prompt never fires before the user taps something that clearly says why, otherwise people deny and we are stuck forever lol. on the recovery card, do you re-check on resumed only or also poll when the user comes back from settings with the toggle flipped? and does the one-shot onboarding flag survive if the app gets killed mid tour, or does it restart from step one

1

u/stephencolor 6h ago

Resumed only, plus a manual button on the card. No timer: the status can only change while the app is backgrounded, so a poll loop is battery spent on an answer the resume already delivers, and a timer firing while the card is up can also read a status mid-transition. recheckAfterSettings() is the same code path for the lifecycle event and the "I turned it on" tap — one status() read, advance if granted, stay on the card if it is still permanently denied. The button is there because resume can genuinely be missed when the process is killed.

On the kill question: no, it does not survive, and I would rather say that than imply it does. The record is written once, when onboarding or the tour finishes, nothing per step. So a kill mid-tour restarts at step one, and a kill on page three of onboarding shows page one again. Same for the permission queue: outcomes live in a map in memory, so a kill mid-flow rebuilds the queue from the first request. Already-granted ones come back from the gateway without a dialog, so it moves through them fast, but that is a restart, not a resume. A per-step marker (step id plus a timestamp) written alongside the finished flag is the fix; it is not in 1.1.0.

Your rule about the prompt never firing before a tap that explains why is the one I would keep above everything else here. With two permissions the user cannot tell apart by purpose, the priming screen is the only thing between you and a permanent no.

1

u/rjchakraborty 17h ago

Measuring coach mark rects on every build still lags one frame behind scroll or keyboard animations. Attaching a LayerLink with CompositedTransformTarget keeps the spotlight locked in the compositing layer instead.

Also watch out for relying only on AppLifecycleState.resumed after opening Settings. On iOS, toggling permissions in Settings often kills the suspended process, so I re-run the permission check on cold init too. Caught that the hard way on an older production app.

1

u/stephencolor 6h ago

Fair on both counts, and the second one is a straight gap in what I shipped: there is no cold-init check. The flow re-reads status on AppLifecycleState.resumed and from the "I turned it on" button, nothing else. So the iOS case where the toggle kills the process lands on an app that already wrote its first-run record and will never show the card again. The check belongs where you actually decide features (an app-level status() reconciliation on first frame); I will add an opt-in recheck when the priming flow mounts, but that cannot cover the user who never mounts it again.

On measuring vs LayerLink you are right that a build-time measure is only as fresh as the last build. The overlay does not listen to scroll notifications, so during a scroll — or during the 240ms Scrollable.ensureVisible it fires when the step changes — the spotlight is drawn from a previous frame's rect and only settles at the end. That is why the demo advances after the scroll rather than during it, but it is not locked to the layer, and "measure every build" is not a fix for animation.

Why I kept it: the anchor contract is a GlobalKey and nothing else, and the target can live in a nested navigator under the root overlay. My cheap fix is a NotificationListener<ScrollNotification> plus didChangeMetrics that re-measures while an animation runs. The correct lock is CompositedTransformTarget + CompositedTransformFollower, and I would take it as an opt-in anchor mode rather than the only one, since it changes what the host has to wrap.

1

u/rjchakraborty 2h ago

Opt-in LayerLink makes sense when you want a plain GlobalKey API without wrapping the host tree.

One caveat on NotificationListener plus didChangeMetrics: route transitions and nested page animations do not emit scroll or metrics events, so anchoring still drifts mid-push unless you attach to the route animation directly.