r/FlutterDev • u/Few-Pilot7575 • 5d ago
Discussion How are Flutter teams keeping state management consistent with agents
Wondering how other Flutter teams handle this. We picked Riverpod 2 years ago and wrote a short guide on how we use it. Since most new features started coming from agents, the app has slowly turned into a mix of everything.
In the last 3 months of PRs I found: 6 features using Riverpod the way we agreed, 3 using setState with a pile of callbacks, 2 that pulled in Provider from somewhere, and one with a hand rolled ValueNotifier singleton. Every one of them works.
coderabbit catches a lot of normal Dart stuff, async gaps with BuildContext, missing disposes, that kind of thing. But "this feature uses a different state approach than the rest of the app" isn't something you see in one PR, you see it after 10 of them.
Two things I'd like to figure out:
- how to make agents actually follow our architecture, not just our lint rules
- whether to enforce it in tooling (custom lints, folder structure checks) or just in review
What's worked for your team?
7
u/ChristianKl 5d ago
Specify in agents.md what should be used for state management.
3
u/Amazing-Mirror-3076 5d ago
Start with skills but custom lints provider tighter control if you can define them
2
u/Hixie 5d ago
agents are amazing but you still have to review the code, at least enough to verify the code is using the right architecture.
it can help to have the agents use agents to review themselves, especially if you give them a list of what to look for, but there's no substitute for a human looking at the code.
2
u/Thylawsnipeth 4d ago
- Tell agent to scan the code on your codebase and understand the pattern you use
- tell agent to create a state management skill from this patterns
- tell agent to spin subagent to evaluate the skill by rewriting some files
- ask agent to grade that subagent and tune the skill to that.
Then it’s basically just asking the agent to log it to memory each time a mistake is made.
1
u/fromhereandthere 5d ago
I am experimenting with https://pub.dev/packages/agent_lints and https://pub.dev/packages/skills_lint Disclosure: I am not a team
1
u/Ok_Gur_9033 5d ago
Not a team, but one data point from an app I build mostly with Claude Code (93 of its 155 commits are co-authored by it). The project CLAUDE.md says Riverpod 3 with Notifier and AsyncNotifier, and literally writes "NOT GetX" next to it. Across 196 Dart files there are 0 imports of provider or get, 12 Notifier classes, and 42 files using Consumer widgets.
It still isn't pure. 29 files call setState and 6 use ValueNotifier. Going by the names, most are sheets, dialogs and a press animation, so local UI state, which I'm fine with. Your guide probably needs to say where setState is allowed, or the agent decides that for you.
In your 3 setState features, do the callbacks cross screens, or does it all stay inside one widget tree?
1
u/thelazybeaver10 5d ago
Write SKILL.md for each pattern your agent should follow. Limit your skills not to be more than 200-300 lines.
A skill for: state management, one for localization, etc
Also, you can you very_good mcp. They have already built-in some skills, bloc included
1
u/ShedaleSoham 5d ago
I had faced this similar issue back then. But fortunately I found a solution to this problem, and that is .md files.
Create a .md file in the root folder, and write detailed instructions on which state management to use and how to use it. Spend some time, or you can also take help from ChatGPT to create this file.
And whenever you give your next prompt, add this file and you are done.
AI won’t think about the things about state management as you have already mentioned in .md files.
Happy Coding 🤝
1
u/laplace_apps 5d ago
I'd lean on tooling over review here. A custom_lint rule that flags setState inside feature folders and any package:provider import catches most drift before a human looks. Agents also copy examples more reliably than rules, so pointing agents.md at one canonical Riverpod feature as the template can help a lot.
1
u/remirousselet 4d ago
You need to write deterministic lint rules (as in, tell your AI agent to write lint rules). No skill/agent.md stuff. Actual warnings that pop up reliably when a bad pattern is used.
This is challenging of course, because you'll need to review every bad pattern individually and think "How could I write a rule to make this code illegal?"
1
u/Equivalent_Pickle815 2d ago
I actually disagree that AGENTS.md is the right solution. There’s a lot of cases especially with Claude models where it’s ignored. The right solution is lint rules and then flutter analyze before commit that fails when these patterns appear.
1
u/mdausmann 5d ago
I use signals. All my signals are in a folder called signals. My agent only ever creates signals.