Skip to content
Agentmart
Submit a tool

riverpod-codegen-and-hooks

Use Riverpod code generation (@riverpod, riverpod_generator) and hooks (hooks_riverpod, HookConsumerWidget, flutter_hooks with Riverpod).

Skill by serverpod

IndexedBSD-3-Clause★ 10
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/serverpod-riverpod-codegen-and-hooks

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Use Riverpod code generation (@riverpod, riverpod_generator) and hooks (hooks_riverpod, HookConsumerWidget, flutter_hooks with Riverpod). Use when the user asks about @riverpod, code generation, riverpod_generator, when to use codegen, or using flutter_hooks with Riverpod (HookConsumerWidget, HookConsumer).

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/riverpod-codegen-and-hooks

What's inside

Skill name
riverpod-codegen-and-hooks
Description
Use Riverpod code generation (@riverpod, riverpod_generator) and hooks (hooks_riverpod, HookConsumerWidget, flutter_hooks with Riverpod). Use when the user asks about @riverpod, code generation, riverpod_generator, when to use codegen, or using flutter_hooks with Riverpod (HookConsumerWidget, HookConsumer).
License
BSD-3-Clause
Instructions
102 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Riverpod — Code generation and hooks

## Code generation

Code generation is **optional** in Riverpod. It changes the syntax for defining providers: you write an annotated function or class and the generator produces the provider. Use it if you already use code generation (e.g. Freezed, json_serializable); otherwise the extra build step may not be worth it. See riverpod-getting-started for setup (build_runner, riverpod_generator).

### Benefits

- Clearer syntax: no manual provider type (Provider vs FutureProvider etc.); Riverpod infers it.
- Parameters: any parameters (named, optional, defaults) instead of a single family parameter.
- Stateful hot-reload for Riverpod code.
- Better debugging via generated metadata.

### Syntax

**Functional provider** (sync):

```dart
@riverpod
String example(Ref ref) {
  return 'foo';
}
```

**Class-based provider** (sync, with methods for side effects):

```dart
@riverpod
class Example extends _$Example {
  @override
  String build() => 'foo';
  // Add methods to mutate state
}
```

**Async:** Use `Future`/`FutureOr`/`Stream`; async functions get AsyncValue and loading/error handling automatically. **Auto-dispose:** On by default with codegen. Disable with `@Riverpod(keepAlive: true)`.

```dart
@riverpod
String example1(Ref ref) => 'foo';

@Riverpod(keepAlive: true)
String example2(Ref ref) => 'foo';
```

**Parameters:** Add parameters to the function (consistent == required):

```dart
@riverpod
Future<User> fetchUser(Ref ref, {required int userId}) async {
  final json = await http.get('api/user/$userId');
  return User.fromJson(json);
}
```

Manual equivalent would be `FutureProvider.autoDispose.family<User, int>(...)`. See riverpod-providers and riverpod-family for concepts.

---

## Hooks

**Hooks** come from [flutter_hooks] (separate from Riverpod). They are for **local** widget state (e.g. TextEditingController, AnimationController) and can replace StatefulWidget or builder nesting. Use them only if you want hooks; they are not required for Riverpod. Newcomers should avoid hooks at first.

### Using hooks and Riverpod together

You need both **flutter_hooks** and **hooks_riverpod**. Then either:

**Option 1: HookConsumerWidget** — One base class that supports both hooks and ref:

```dart
class Example extends HookConsumerWidget {
  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final counter = useState(0);
    final value = ref.watch(myProvider);
    return Text('Hello $counter $value');
  }
}
```

**Option 2: HookConsumer** — Builder that combines HookBuilder + Consumer (works with flutter_riverpod only if you nest them; hooks_riverpod provides HookConsumer):

```dart
return HookConsumer(
  builder: (context, ref, child) {
    final counter = useState(0);
    final value = ref.watch(myProvider);
    return Text('Hello $counter $value');
  },
);
```

**Option 3:** Nest `Consumer` and `HookBuilder` (no hooks_riverpod needed).

### Rules of hooks

- Use hooks only in the **build** method of a widget that extends **HookWidget** (or HookConsumerWidget).
- Do not use hooks conditionally or in loops; call order must be stable.

See riverpod-consumers for Ref in widgets and the official docs for full codegen/hooks details.

From serverpod/skills-registry, BSD-3-Clause.

More from serverpod/skills-registry

Signals

Stars
10
Forks
0
Open issues
0
Last commit (this folder)
Mar 7, 2026 (7 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
BSD-3-Clause
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from serverpod

Cite this page

riverpod-codegen-and-hooks skill. Agent Mart. https://agentmart.dev/skills/serverpod-riverpod-codegen-and-hooks (last updated 2026-10-24)