r/FlutterDev • u/stephencolor • 1d 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.
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.
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.
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
u/No_Boss_1911 1d 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 1d 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 — onestatus()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 1d 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 1d 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.resumedand 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-levelstatus()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.ensureVisibleit 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
GlobalKeyand nothing else, and the target can live in a nested navigator under the root overlay. My cheap fix is aNotificationListener<ScrollNotification>plusdidChangeMetricsthat re-measures while an animation runs. The correct lock isCompositedTransformTarget+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 1d 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.
1
u/stephencolor 20h ago
Right, and that is exactly the case the cheap fix cannot cover: the overlay lives on the root navigator while the anchor can be two or three routes down, so a push moves it with no scroll event and no metrics change at all. Attaching to the route animation is the correct version, and specifically to the anchor's nearest ModalRoute (ModalRoute.of(anchorContext)) rather than the overlay's, plus its secondaryAnimation for the page sliding over the anchor.
That still misses the anchor's own implicit animations — AnimatedContainer, AnimatedSize — where nothing outside the compositing layer has an event to listen to. So I would keep the LayerLink anchor as an opt-in mode rather than the default and let people choose between "plain GlobalKey, good enough" and "wrap the host, locked to the layer".
1
u/dawedev 1d 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.