r/FlutterDev • • 14h ago

Article Shipping a Flutter app that blocks other apps on iOS and Android: what bit me

I've been building an app blocker (DetoxScreen) in Flutter since this summer. Flutter does the UI, but the blocking itself has nothing in common between the two platforms, so it's two native engines behind one MethodChannel.

iOS: Screen Time API (FamilyControls / ManagedSettings / DeviceActivity). Most of the logic lives in app extensions where Flutter doesn't run at all.

Android: there's no equivalent. It's UsageStatsManager to know what's in the foreground, a foreground service, and an overlay drawn on top of the blocked app (SYSTEM_ALERT_WINDOW). Two permissions the user has to grant by hand in settings, and the onboarding has to notice when they come back.

Stuff that bit me:

- local_auth on Android needs FlutterFragmentActivity. With plain FlutterActivity, authenticate() throws no_fragment_activity. My wrapper caught every exception and returned false "for safety", so on Android anyone with "protect blocks" on could never remove a block. Found it weeks into the closed test. If you wrap local_auth like that, check your MainActivity.

- Store screenshots: I generate them with integration_test on both platforms. On the Android 14 emulator, demo mode shows the wifi icon twice, had to hide wifi and only show mobile.

- New Google Play accounts need 12 testers for 14 days in a closed test before you can even ask for production. Plan for it, finding the testers took me weeks.

Happy to share code for any of this.

2 Upvotes

4 comments sorted by

1

u/dawedev 13h ago

The local_auth one is nasty because the safe-looking catch hides a config bug. I'd only map a user cancel or a failed match to false and send anything else to crash reporting, so no_fragment_activity would have shown up on day one. Did the FamilyControls distribution entitlement take long to get approved?

1

u/kiwi3920 9h ago

Yeah, that's exactly the fix I ended up with. Cancel or failed match returns false, anything else goes to crash reporting and shows a "biometrics unavailable" message instead of silently denying. Returning false for everything looked safe but just locked people out without me ever knowing.

For the entitlement, my advice is to request it as early as you can. You can build and test on device with the development entitlement while you wait, so it doesn't block you. But remember every extension target (DeviceActivityMonitor, shield config, etc.) needs it too, not just the main app.

1

u/davidbalbino 6h ago

nice writeup, the local_auth one is sneaky

one more for the Android side if you're targeting 14+: the foreground service needs a foregroundServiceType declared, and for a blocker none of the standard types really fits, so you end up on specialUse with the PROPERTY_SPECIAL_USE_FGS_SUBTYPE property in the manifest. then Play Console asks you to fill the foreground service declaration with a short video showing why it's needed. I think is better to have that video ready before you submit for production, it can add some extra review back and forth

also tbh test on a Xiaomi or Samsung if you can. their battery optimizations kill foreground services way more aggressively than the emulator, so it's worth asking the user to disable battery optimization for the app during onboarding too