← All posts

4 min read

How I Audit an AI-Generated Flutter Codebase

How I audit Flutter apps written with Cursor, Claude or similar tools: what to run first, how to check security and payments, and how to rank fixes.

  • Flutter
  • AI
  • Code Quality
  • Maintenance
Cover illustration for How I Audit an AI-Generated Flutter Codebase

Reviewing AI-written code is different from reviewing a colleague’s. A colleague leaves a trail of reasoning. Generated code can look tidy and confident while hiding decisions nobody actually made.

The process below builds on the routine I use for taking over an existing Flutter app, with extra attention on the failures AI tools are prone to. The goal at the end is a short written report that ranks problems by business risk, so the owner can decide what to pay for.

1. Build it exactly as it is

Before forming any opinion, I get the current app running:

fvm use <version from .fvmrc or pubspec.lock>
flutter pub get
flutter analyze
flutter build apk --release

Generated projects often have a loose environment constraint and a pile of packages that were added and forgotten. If there’s no lockfile, I note that as a finding, because nobody can say which versions the working build used.

I always run a release build. Debug mode hides a lot, and release is what users get.

2. Search for secrets

Next, I look for anything that shouldn’t ship:

grep -RInE "sk-[a-zA-Z0-9]|sk_live|service_role|PRIVATE KEY|api[_-]?key" lib/ android/ ios/ .env* assets/
git log --all -p -S"sk_live" -- . | head

I also check pubspec.yaml, because a .env file listed under assets gets bundled into the app. That one looks like good practice and isn’t.

A secret that has ever been committed or shipped counts as leaked. Removing it isn’t enough. It has to be rotated.

3. Test data access as the wrong user

For Firebase, I read firestore.rules and storage.rules. For Supabase, I check that row-level security is on for every table and that the policies say what they appear to say. For a custom API, I look at whether each endpoint checks ownership or only checks that a token exists.

Then I prove it. I create two test users, sign in as A and request B’s records directly. Reading rules catches most issues, and this test catches the rest.

4. Read the money path

Payment code gets a line-by-line read. My questions:

  • Does access depend on a client-side “success” or a verified server event?
  • Are webhooks verified, and is a repeat delivery safe?
  • What happens on a failed renewal, a refund or a cancellation?
  • Can a purchase be restored on a new phone?
  • For digital goods, is the app using the store’s in-app purchase where it has to?

5. Map the structure

Now I look at how the code is organised, without judging style. I want to know how many ways the app does the same job.

# How big are the screens?
find lib -name "*.dart" | xargs wc -l | sort -n | tail -20

# How many ways does this app talk to the network or manage state?
grep -RIlE "http\.(get|post)|Dio\(" lib | wc -l
grep -RIlE "setState|ChangeNotifier|StateNotifier|Bloc<|Provider\(" lib | wc -l

Typical signs of generated code:

  • 800-line widgets holding UI, networking and business rules together
  • Several API clients, each with its own error handling
  • Two state management approaches, because the prompt changed halfway through
  • Helpers and models that nothing calls
  • Comments that describe intentions the code doesn’t carry out

Mixed patterns on their own aren’t a defect. They matter when the same rule lives in several places, because then a fix can only ever be partial.

6. Break it on purpose

I run the main flows on a real device and try to make them fail: airplane mode mid-request, double taps on submit, a killed app during payment, an expired session, a huge image, text scaled up to 200%, and an older phone. Then I run flutter analyze and look at warnings about BuildContext across async gaps and unawaited futures, which often point to real crashes.

If tests exist, I read them as well as run them. AI-written tests sometimes assert whatever the code already does, or mock so much that nothing real gets exercised.

7. Check it against the stores

I check target SDK, iOS build tools, permission text, account deletion, privacy details, and whether personal data goes to a third-party AI service. Apple’s guidelines now call out that last one specifically, and it needs clear disclosure and explicit permission from the user first. A hidden line in the privacy policy won’t cover it.

8. Write it up by risk

The deliverable is one page a non-technical owner can act on:

Level Meaning Examples
Stop Can cost money or expose data now Leaked secret keys, open database rules
Before launch Will cause failures or rejection Payment gaps, no crash reporting, missing account deletion
Soon Slows every future change Duplicated logic, mixed state management
Later Worth doing when you’re nearby Naming, dead code, smaller widgets

Each item gets a plain-English explanation and a rough size. I also give a recommendation on cleanup versus rebuild, and I won’t make that call before reading the code. A rebuild is expensive advice, and it’s also the easiest advice to give.

Using AI during the audit

I use AI tools here too, mainly to summarise unfamiliar modules and trace call paths. I don’t take their word on security or money. Those conclusions come from reading the code and running the test myself.

Takeaways

  • Build it in release mode before forming opinions.
  • Treat any shipped secret as compromised.
  • Prove access control by attacking it as a second user.
  • Read the payment path line by line.
  • Rank findings by business risk so the owner can choose.

If you have a Flutter app written with AI and want a second pair of eyes before it goes further, get in touch.

Comments

Questions, corrections or your own experience — leave a comment below (GitHub sign-in).