flutter-change-notifier — Claude Code skill: what it does
flutter-change-notifier — a skill that teaches the agent to use ChangeNotifier and provider for Flutter state management: models, providers, Consumer, rebuild optimization.
MIT ★ 674 updated 2026-10-29
/plugin marketplace add evanca/flutter-ai-rules
/plugin install flutter-ai-skills@flutter-ai-rulesWhat flutter-change-notifier does
The agent builds a model with private state and methods that call notifyListeners() after changes. The model is wrapped in ChangeNotifierProvider (or MultiProvider for several models), which disposes of it automatically. Widgets subscribe via Consumer<T> with an explicit type; constant parts go into the child parameter to avoid rebuilding them.
To call methods without subscribing to changes, the agent uses Provider.of<T>(context, listen: false). Consumer is placed as deep in the widget tree as possible to narrow the rebuild scope. Without proper tree structure and provider placement, large parts of the UI will rebuild unnecessarily.
The skill includes unit test rules for models: checking state changes and listener calls via addListener. The agent does not mutate widgets directly, it rebuilds them with new data.
What it helps with
- set up a
ChangeNotifiermodel with private state andnotifyListeners() - wrap a model in
ChangeNotifierProviderorMultiProvider - subscribe a widget to changes via
Consumer<T>with rebuild optimization - call a model method without subscribing via
Provider.of<T>(context, listen: false) - write a unit test for
ChangeNotifierwith listener verification
Example prompts for the agent
- Create a cart model with
ChangeNotifier, add and clear methods - Wrap the app in
ChangeNotifierProviderforCartModel - Add
Consumer<CartModel>to display total price, move constant parts intochild
How to install flutter-change-notifier
1Plugin marketplace
/plugin marketplace add evanca/flutter-ai-rules/plugin install flutter-ai-skills@flutter-ai-rulesThis installs the whole flutter-ai-skills plugin with all its skills
2Skills CLI (Vercel)
npx skills add evanca/flutter-ai-rules --skill flutter-change-notifier -a claude-code3Manually: put the files in place
~/.claude/skills/flutter-change-notifier/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/flutter-change-notifier/
1Skills CLI (Vercel)
npx skills add evanca/flutter-ai-rules --skill flutter-change-notifier -a codex2Manually: put the files in place
.agents/skills/flutter-change-notifier/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add evanca/flutter-ai-rules --skill flutter-change-notifier -a cursor2Manually: put the files in place
.cursor/skills/flutter-change-notifier/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install evanca/flutter-ai-rules skills/flutter-change-notifier2Manually: put the files in place
.github/skills/flutter-change-notifier/SKILL.md1Skills CLI (Vercel)
npx skills add evanca/flutter-ai-rules --skill flutter-change-notifier -a gemini-cli2Platform CLI
gemini skills install https://github.com/evanca/flutter-ai-rules --path skills/flutter-change-notifierManually: put the files in place
.devin/skills/flutter-change-notifier/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about flutter-change-notifier
How to install flutter-change-notifier in Claude Code?
Run /plugin marketplace add evanca/flutter-ai-rules, then /plugin install flutter-ai-skills@flutter-ai-rules. Via CLI: npx skills add evanca/flutter-ai-rules --skill flutter-change-notifier -a claude-code. The file will be in ~/.claude/skills/flutter-change-notifier/SKILL.md.
What does flutter-change-notifier do?
It teaches the agent to work with ChangeNotifier and provider for Flutter state management: create models, wrap them in providers, subscribe widgets via Consumer, optimize rebuilds, and test models.
When to use listen: false in Provider.of?
When you need to call a model method in a callback (e.g., onPressed) but do not need to subscribe to state changes. The widget will not rebuild on every notifyListeners().
Source text
SKILL.md · MIT
---
name: flutter-change-notifier
description: "Use when setting up ChangeNotifier models, providing them to the widget tree, consuming state with Consumer or Provider.of, or optimizing rebuilds."
license: MIT
---
# Flutter ChangeNotifier Skill
This skill defines how to correctly use `ChangeNotifier` with the `provider` package for state management in Flutter.
---
## 1. Model
Extend `ChangeNotifier` to manage state. Keep internal state **private** and expose **unmodifiable views**. Call `notifyListeners()` on every state change.
```dart
class CartModel extends ChangeNotifier {
final List<Item> _items = [];
UnmodifiableListView<Item> get items => UnmodifiableListView(_items);
void add(Item item) {
_items.add(item);
notifyListeners();
}
void removeAll() {
_items.clear();
notifyListeners();
}
}
```
- Place shared state **above** the widgets that use it in the widget tree.
- Never directly mutate widgets or call methods on them to change state — rebuild widgets with new data instead.
---
## 2. Providing the Model
```dart
ChangeNotifierProvider(
create: (context) => CartModel(),
child: MyApp(),
)
```
- `ChangeNotifierProvider` **automatically disposes** of the model when it is no longer needed.
- Use `MultiProvider` when you need to provide multiple models:
```dart
MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => CartModel()),
ChangeNotifierProvider(create: (_) => UserModel()),
],
child: MyApp(),
)
```
---
## 3. Consuming State
### Consumer
```dart
Consumer<CartModel>(
builder: (context, cart, child) => Stack(
children: [
if (child != null) child,
Text('Total price: ${cart.totalPrice}'),
],
),
child: const SomeExpensiveWidget(), // rebuilt only once
)
```
- Always specify the generic type (`Consumer<CartModel>`, not `Consumer`).
- Use the `child` parameter to pass **widgets that don't depend on the model** — they are built once and reused.
- Place `Consumer` widgets **as deep in the widget tree as possible** to minimize the scope of rebuilds:
```dart
HumongousWidget(
child: AnotherMonstrousWidget(
child: Consumer<CartModel>(
builder: (context, cart, child) {
return Text('Total price: ${cart.totalPrice}');
},
),
),
)
```
### Provider.of with listen: false
Use `Provider.of<T>(context, listen: false)` when you only need to **call methods** on the model, not react to state changes:
```dart
Provider.of<CartModel>(context, listen: false).removeAll();
```
---
## 4. Optimization Rules
- Do **not** wrap large widget subtrees in a `Consumer` if only a small part depends on the model.
- Avoid rebuilding widgets unnecessarily — structure your widget tree and provider usage carefully.
- Use `listen: false` in callbacks (e.g., `onPressed`) where you trigger actions but don't need rebuilds.
---
## 5. Testing
Write **unit tests** for your `ChangeNotifier` models to verify state changes and notifications:
```dart
test('adding item updates total', () {
final cart = CartModel();
var notified = false;
cart.addListener(() => notified = true);
cart.add(Item('Book'));
expect(cart.items.length, 1);
expect(notified, isTrue);
});
```
---
## References
- [Flutter Website GitHub Repository](https://github.com/flutter/website)
© Ivanna Kaceviča · MIT · evanca/flutter-ai-rules