r/FlutterDev • u/AliXarza • Oct 27 '26
Discussion We audited our own Flutter app as a first-time user. Three bugs our tests and our own phones never showed.
https://amxnexus.com/en/store/syncWe build a role-based internal messaging app (Flutter + Firestore, anonymous auth, invite codes, one device per account). Before shipping we did one pass with strict rules: UI only, no database access, clean install, realistic data (long Arabic names, a 4000x3000 photo), and a wipe of app data halfway through to simulate a new phone.
Three things came out of it that I think are generic enough to be useful.
1. A lock screen swapped into home does not lock anything that is pushed
We had roughly this:
home: (pinEnabled && isLocked) ? const LockScreen() : const HomeScreen(),
On resume we set isLocked = true. That rebuilds home, but any route pushed on top of it (compose, admin) is still on top. So: open the compose screen, background the app, come back, and you are looking at compose with no PIN prompt. The lock screen is sitting under it.
What we do now is draw the lock in MaterialApp.builder, above the Navigator, and take the real app offstage:
builder: (context, child) => Stack(
fit: StackFit.expand,
children: [
Offstage(
offstage: locked,
child: ExcludeFocus(excluding: locked, child: child!),
),
if (locked)
HeroControllerScope.none(
child: Navigator(
onGenerateRoute: (_) =>
MaterialPageRoute(builder: (_) => const LockScreen()),
),
),
],
),
Notes on that:
The lock needs its own Navigator so its text field has an Overlay.
Without HeroControllerScope.none you get "A HeroController can not be shared by multiple Navigators" in debug.
Offstage keeps the route stack alive, so a half-written message survives the lock. ExcludeFocus stops the hidden field from keeping the keyboard.
Trade-off: we lock on paused, so opening the system photo picker also locks. The pending pick still resolves after unlock because the widget tree was never torn down. Some people would rather use a grace period; we have not added one.
2. Sequential awaits in one try block turn one denied write into a silent total failure
Creating an organization did this:
try {
await saveCompany(c);
await saveUser(admin);
await saveInvite(invite);
for (final r in roles) await saveRole(r);
status = 'online';
} catch (_) {
status = 'offline';
}
Our security rules denied the first write (company document). Everything after it never ran. Locally the app was fine because all of it was in local storage, and a separate listener flipped the status badge back to "online" a moment later. The admin's invite code simply did not exist server-side, so on any other device it was "invalid code".
The manual "resync" button had the same shape and the same first write, so it failed every time with a message telling the user to check their internet.
Fix was boring: run each write independently, collect a boolean, report honestly.
Future<bool> _writeAll(List<Future<void> Function()> ops) async {
var allOk = true;
for (final op in ops) {
try { await op(); } catch (_) { allOk = false; }
}
return allOk;
}
A batch would be the alternative, and for strict consistency it is the better tool. We chose independent writes here because partial success is strictly more useful to the user than none: with only the invite and the admin record uploaded, the account is at least reachable from another device.
The real lesson was about verification. "It synced" was being judged from the device that created the data. That device can never tell you.
3. One-device binding with a single admin is a lockout waiting to happen
Accounts bind to a device ID on first sign-in. Admins can reset an employee's binding. Nothing could reset the admin's. New phone or reinstall, and the organization is unreachable.
We added a recovery key generated at setup: 12 characters from an alphabet without O/0/I/1, shown once, only a SHA-256 of the normalised key stored on the user record. Sign-in code plus recovery key rebinds the admin to the new device.
Trade-offs I am not fully happy with:
The hash is unsalted beyond a static prefix. With about 60 bits of entropy in the key that is acceptable for now, but a per-user salt and a slow hash would be better.
Verification happens client-side against a hash the client can read. The proper version checks it in a Cloud Function and never exposes the hash.
While fixing this we found the device binding was not even being uploaded at first sign-in on a fresh device. Our write helper returned early when there was no "current organization" yet, and login called it one line before setting that. It only worked because a later push-token save happened to carry the field along.
Smaller findings that only showed up with real data
Structured message fields came back from Firestore in a different key order than we wrote them, so "old price" rendered above "product name". We now render in the template's declared order instead of map order.
No flutter_localizations, so the Material date and time pickers were English inside an RTL Arabic UI.
image.decodeImage on a 12MP photo on the UI thread froze the app for seconds. Moved to compute.
The feed showed every message to every employee. Recipient roles were only used for display.
What we changed in process
A release now needs one full pass on a clean install with realistic data, including a second "device" for anything that claims to sync. It costs about an hour and found more than our test suite did, which says as much about our test suite as about the method.
Happy to go into any of these, especially if someone has a cleaner pattern for the lock overlay.
1
u/ObjectiveAddress3051 Oct 28 '26
drawing the lock in MaterialApp.builder above the navigator is the right call imo, swapping home never covers anything that's already pushed. one thing i'd check on android is the recents screen. the snapshot of the last frame can still show the content unless you set FLAG_SECURE or blank it on pause.
1
u/No_Boss_1911 Oct 29 '26
the offstage trick to keep the route stack alive is neat, half written message surviving the lock is a good detail. i hit something similar with my breathing timer, backgrounding the app was resetting the session on pause. hard rule for me is the timer and audio cue cant lose their place when the app goes away and comes back. did you key the lock off paused only or also inactive, and did that change the picker behavior
3
u/Scroll001 Oct 27 '26
Wouldn't brag about making intern level mistakes in my app
1
u/nian2326076 Oct 29 '26
It sounds like your issue with the lock screen might be more about state management in Flutter. Using a state management solution like Provider or Riverpod could help with app navigation and lock status.
If you want to improve your technical interview skills, PracHub offers a range of technical interview questions to practice with. This can help you prepare for similar challenges in your interviews.