{"slug":"provider","title":"provider","summary":"Use when setting up providers, consuming state, optimizing rebuilds, using ProxyProvider, or migrating from deprecated providers (Provider package).","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-08-30T09:57:20.579832Z","repo":{"url":"https://github.com/evanca/flutter-ai-rules","stars":644,"forks":67,"license":"MIT","updatedAt":"2026-09-14T07:51:38Z"},"bodyHtml":"<hr>\n<h2>name: provider\ndescription: \"Use when setting up providers, consuming state, optimizing rebuilds, using ProxyProvider, or migrating from deprecated providers (Provider package).\"\nlicense: MIT</h2>\n<h1>Provider Skill</h1>\n<p>This skill defines how to correctly use the <code>provider</code> package in Flutter applications.</p>\n<hr>\n<h2>1. Provider Types</h2>\n<table>\n<thead>\n<tr>\n<th>Provider</th>\n<th>Use for</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>Provider</code></td>\n<td>Exposing any immutable value</td>\n</tr>\n<tr>\n<td><code>ChangeNotifierProvider</code></td>\n<td>Mutable state with <code>ChangeNotifier</code></td>\n</tr>\n<tr>\n<td><code>FutureProvider</code></td>\n<td>Exposing a <code>Future</code> result</td>\n</tr>\n<tr>\n<td><code>StreamProvider</code></td>\n<td>Exposing a <code>Stream</code></td>\n</tr>\n<tr>\n<td><code>ProxyProvider</code> / <code>ChangeNotifierProxyProvider</code></td>\n<td>Objects that depend on other providers</td>\n</tr>\n</tbody>\n</table>\n<hr>\n<h2>2. Setup</h2>\n<pre><code>MultiProvider(\n  providers: [\n    Provider&lt;Something&gt;(create: (_) =&gt; Something()),\n    ChangeNotifierProvider(create: (_) =&gt; MyNotifier()),\n    FutureProvider&lt;String&gt;(create: (_) =&gt; fetchData(), initialData: ''),\n  ],\n  child: MyApp(),\n)\n</code></pre>\n<ul>\n<li>Use <code>MultiProvider</code> to group multiple providers and avoid deeply nested trees.</li>\n<li><code>ChangeNotifierProvider</code> <strong>automatically disposes</strong> the model when it is no longer needed.</li>\n<li><strong>Never</strong> create a provider's object from variables that can change over time — the object won't update when the variable changes. Use <code>ProxyProvider</code> instead.</li>\n<li>If you have 150+ providers, consider mounting them over time (e.g., during a splash screen) rather than all at once to avoid <code>StackOverflowError</code>.</li>\n</ul>\n<hr>\n<h2>3. Consuming State</h2>\n<p>Always specify the <strong>generic type</strong> for type safety:</p>\n<pre><code>// Listen and rebuild on change — only valid inside build() or a Provider's update method\nfinal count = context.watch&lt;MyModel&gt;().count;\n\n// Access without listening — use in callbacks, not inside build()\ncontext.read&lt;MyModel&gt;().increment();\n\n// Listen to only part of the state\nfinal count = context.select&lt;MyModel, int&gt;((m) =&gt; m.count);\n</code></pre>\n<p>Use <code>Consumer&lt;T&gt;</code> or <code>Selector&lt;T, R&gt;</code> widgets when you need fine-grained rebuilds and cannot access a descendant <code>BuildContext</code>:</p>\n<pre><code>Consumer&lt;MyModel&gt;(\n  builder: (context, model, child) =&gt; Text('${model.count}'),\n  child: const ExpensiveWidget(), // rebuilt only once\n)\n\nSelector&lt;MyModel, int&gt;(\n  selector: (_, model) =&gt; model.count,\n  builder: (_, count, __) =&gt; Text('$count'),\n)\n</code></pre>\n<hr>\n<h2>4. ProxyProvider</h2>\n<p>Use <code>ProxyProvider</code> or <code>ChangeNotifierProxyProvider</code> for objects that depend on other providers or values that can change:</p>\n<pre><code>MultiProvider(\n  providers: [\n    Provider&lt;Auth&gt;(create: (_) =&gt; Auth()),\n    ProxyProvider&lt;Auth, Api&gt;(\n      update: (_, auth, __) =&gt; Api(auth.token),\n    ),\n  ],\n)\n</code></pre>\n<hr>\n<h2>5. Rules</h2>\n<ul>\n<li>Do <strong>not</strong> access providers inside <code>initState</code> or constructors — use them in <code>build</code>, callbacks, or lifecycle methods where the widget is fully mounted.</li>\n<li>You can use <strong>any object</strong> as state, not just <code>ChangeNotifier</code>; use <code>Provider.value()</code> with a <code>StatefulWidget</code> if needed.</li>\n</ul>\n<hr>\n<h2>6. Debugging</h2>\n<p>Implement <code>toString</code> or <code>DiagnosticableTreeMixin</code> to improve how your objects appear in Flutter DevTools:</p>\n<pre><code>class MyModel with DiagnosticableTreeMixin {\n  final int count;\n  MyModel(this.count);\n\n  @override\n  String toString() =&gt; 'MyModel(count: $count)';\n}\n</code></pre>\n<hr>\n<h2>7. Migration: ValueListenableProvider</h2>\n<p><code>ValueListenableProvider</code> is deprecated. Use <code>Provider</code> with <code>ValueListenableBuilder</code> instead:</p>\n<pre><code>ValueListenableBuilder&lt;int&gt;(\n  valueListenable: myValueListenable,\n  builder: (context, value, _) {\n    return Provider&lt;int&gt;.value(\n      value: value,\n      child: MyApp(),\n    );\n  },\n)\n</code></pre>\n<hr>\n<h2>References</h2>\n<ul>\n<li><a href=\"https://github.com/rrousselGit/provider\">Provider GitHub Repository</a></li>\n</ul>\n","files":[{"path":"SKILL.md","sizeBytes":3611,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-08-30T09:58:48.938849Z","sha256":"32DC14EC4F93A20F68A07326401E37619410E8DD794EF4457E60DA1221A3065D","sizeBytes":1694},"review":null,"source":{"repositoryUrl":"https://github.com/evanca/flutter-ai-rules","path":"skills/provider","license":"MIT","commit":"7b9cce235714ae17acbae896b1e8c8627e128f4c","subtreeSha":"80762B6F2D12A565DDCEC742BB8073D15C507905CC65612BC1205756754FC938","lastSyncedAt":"2026-09-29T23:32:26.661053Z"},"reviewedAt":"2026-08-30T10:15:23.187244Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/evanca/flutter-ai-rules/tree/main/skills/provider"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install evanca-flutter-ai-rules@llmmart"},{"target":"git","command":"git clone https://github.com/evanca/flutter-ai-rules.git"}]}