AI mistakes in Flutter, and a checklist
and how to check what I couldn't
What it is
The chapter's closer. And here, something no other chapter has: a list of what you have to check yourself, because I couldn't (article 11.1).
AI mistakes in Flutter
-
Code for an old version. This stack's main problem. Outdated widget and parameter names;
flutter analyzeusually complains. -
!,late,dynamic. Three ways to switch off the emptiness check — the direct analogue ofany,asandts-ignorefrom article 9.6. -
Assignment without
setState. The value changes, the screen doesn't. -
No
dispose. Controllers and subscriptions outlive the widget. -
A network request in
build.buildis called often. -
Stateful with no state. An extra class.
-
No
constwhere the widget doesn't depend on data. Needless recreation. -
An asset not declared in
pubspec.yaml. The error comes when the screen opens, not at build time. -
Only the happy case is built. No loading, error or emptiness (article 11.5).
-
A denied permission isn't handled. "Denied permanently" especially.
-
A second state library added. Because the request didn't name the first one.
-
Fixed sizes. Overflow on a narrow screen.
A Flutter code checklist
1. The analyzer
flutter analyzeThe first and most important step — here it stands in for mypy and tsc.
It catches outdated APIs, forgotten consts, unused things, and some of the
emptiness errors.
2. Run it
flutter runHot reload shows an edit at once, but not every change is picked up:
edits in initState and in declarations often need a full restart. If a
change "didn't apply", restart completely before looking for a bug in the
code.
3. A narrow screen and long text
Run it on a small device or narrow the window. Type in a long name. The yellow-and-black overflow stripe is the commonest finding.
4. The four states
Loading, empty, error, data. For the error, turn off the network on the device.
5. Permissions
Deny the permission. Then deny it permanently. The application has to keep working and explain what to do.
6. Both platforms
If you build for Android and iOS, check on both. The back button, the safe areas and the dialogs behave differently.
How to check this chapter
The examples here weren't run, so — how to satisfy yourself that what is written is right:
Here is an extract from a Flutter handbook: <extract>.
I'm on Flutter 3.38. Is this current for my version?
If anything is outdated or inaccurate, say exactly what,
with a link to the documentation.And the most reliable way is simply to run it. Create an empty project and check whatever looked doubtful:
flutter create test_app && cd test_app && flutter runWhat to tell the AI
Check this Flutter code against the list:
- is the API current for Flutter 3.38
- are there !, late or dynamic, and why
- does every state change go through setState
- do the controllers and subscriptions have a dispose
- are there requests in build
- is there a const where the widget is static
- are loading, error and emptiness implemented
Which of these are there? If none, say so.Cheat sheet
This stack's main mistake is code for an old version. Name yours.
!,late,dynamicare gags, not solutions.Changes only through
setState; close controllers indispose.flutter analyzeis the first checking step, standing in formypyandtsc."It didn't apply" — a full restart first, then look for the bug.
Check: a narrow screen, the four states, a denied permission, both platforms.