Skip to main content
skill CX Codex

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

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add evanca/flutter-ai-rules
/plugin install flutter-ai-skills@flutter-ai-rules
Open on GitHub

What 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 ChangeNotifier model with private state and notifyListeners()
  • wrap a model in ChangeNotifierProvider or MultiProvider
  • 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 ChangeNotifier with listener verification

Example prompts for the agent

  • Create a cart model with ChangeNotifier, add and clear methods
  • Wrap the app in ChangeNotifierProvider for CartModel
  • Add Consumer<CartModel> to display total price, move constant parts into child

How to install flutter-change-notifier

1Plugin marketplace

/plugin marketplace add evanca/flutter-ai-rules
/plugin install flutter-ai-skills@flutter-ai-rules

This 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-code

3Manually: put the files in place

~/.claude/skills/flutter-change-notifier/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/flutter-change-notifier/

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

Similar skills

All skills for Frontend and UI →

From the same set39

The whole set →
flutter_errors This rule connects common Flutter errors to likely layout or state-management causes. Use it when a widget tree fails with overflow, sizing, or build-phase issues. CX Codex +1 ★ 674repo stars code_review The code_review rule for Claude Code sets a review process for changes before merging. It checks branches, files, code, tests, and the PR/MR description. CX Codex +1 ★ 674repo stars flutter-errors flutter-errors is a Claude Code skill that helps diagnose Flutter layout and runtime errors. It activates for RenderFlex overflow, scroll issues, and setState calls during build. CX Codex +1 ★ 674repo stars mocktail Guidance for using Mocktail in Dart and Flutter tests: configure stubs, inspect interactions, and decide when a mock, fake, or real object fits. CX Codex +1 ★ 674repo stars provider Guides agents on architecting Flutter state with the provider package, keeping rebuilds minimal and dependencies reactive. CX Codex +1 ★ 674repo stars mockito mockito is a Claude Code skill for Dart and Flutter tests that guides mock generation, stubbing, and interaction checks. It activates for Mockito testing tasks. CX Codex +1 ★ 674repo stars developing-genkit-dart developing-genkit-dart — a skill for building AI agents with Genkit Dart that tells the agent when to pull in reference docs for the core framework and its plugins. CX Codex +1 ★ 674repo stars firebase-storage firebase-storage is a skill with guidelines for Firebase Cloud Storage in Flutter apps, covering file uploads, downloads, metadata changes, and storage error handling. CX Codex +1 ★ 674repo stars

Project sponsors

Companies that keep this analytics open