본문으로 건너뛰기
Skillpedia
모바일 앱14k · #11270

riverpod

하는 일

이 스킬은 Riverpod 라이브러리로 Flutter 앱의 데이터와 상태를 다루는 방법을 설명합니다. 데이터를 공유하고 업데이트하는 프로바이더 방식을 원하는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓여러 화면에서 데이터를 공유해야 하는 Flutter 앱을 만들 때.
  • ✓서버에서 데이터를 불러와 앱에 보여 줘야 할 때.
  • ✓Flutter 앱 상태의 테스트를 작성하고 싶을 때.

스킬 링크

https://github.com/andrewyng/context-hub/blob/main/content/flutter/skills/state-management/riverpod/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/andrewyng/context-hub/blob/main/content/flutter/skills/state-management/riverpod/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“Riverpod을 사용해 서버에서 제품 목록을 불러오고, 로딩 스피너를 보여 주는 것을 도와주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

스킬은 각 종류의 데이터를 맞는 프로바이더 유형에 연결합니다. 예를 들어 한 번만 불러오는 경우나 실시간 스트림이 필요한 경우입니다. 그다음 이를 앱의 화면에 연결하는 방법을 보여 줍니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Flutter Riverpod State Management

Use this skill when building Flutter state management with riverpod and flutter_riverpod.

Core Rule

  • Use Provider for read-only values and dependency wiring.
  • Use StateProvider for small mutable state.
  • Use FutureProvider for one-shot async loading.
  • Use StreamProvider for reactive streams.
  • Use Notifier or AsyncNotifier for feature state that needs mutation methods.
  • Use autoDispose for short-lived state.
  • Use family when provider output depends on an argument.
  • Use flutter_riverpod in Flutter apps.
  • If you use flutter_riverpod, you usually do not add riverpod separately because the Flutter package brings it in transitively.
  • Current stable line is Riverpod 3.x (riverpod 3.2.1, flutter_riverpod 3.3.1).

Decision Guide

Choose Riverpod when:

  • you want provider-based dependency injection and reactive state in one model
  • state should be derived from other providers
  • async data is a major part of the feature
  • test overrides and scoped state matter
  • you want fewer classes than a Bloc-heavy approach

Choose a different pattern when:

  • the feature is a tiny local state toggle and a simple widget would be enough
  • the logic is better expressed as an explicit event machine

Required Project Setup

For Dart-only code:

  • add riverpod

For Flutter UI code:

  • add flutter_riverpod
  • wrap the app in ProviderScope
  • use ConsumerWidget, Consumer, or ConsumerStatefulWidget where ref is needed

If code generation is used:

  • add riverpod_annotation
  • add riverpod_generator
  • add build_runner

Implementation Pattern

Prefer this structure:

  • providers own state, dependencies, and derived values
  • repositories and APIs stay outside widgets
  • UI reads state with ref.watch
  • UI performs imperative reads with ref.read
  • container-level overrides are used for tests, demos, and environment-specific wiring

Keep providers small and composable. Keep state immutable unless the provider type is specifically meant for mutation. Keep feature logic in providers or notifiers, not in widgets.

Lifecycle Rules

  • Use autoDispose for short-lived screens and transient queries.
  • Use ref.keepAlive() only when you want cached state to survive temporarily.
  • Prefer provider disposal over manual cleanup.
  • In tests and pure Dart code, dispose ProviderContainer when finished.

UI Binding Rules

Use ConsumerWidget when the whole widget depends on providers. Use Consumer when only a small subtree needs access to ref. Use ConsumerStatefulWidget when you need widget lifecycle plus ref. Use select to reduce rebuilds. Use ProviderListener or ref.listen for side effects.

Testing Rules

  • Test providers through ProviderContainer.
  • Override dependencies instead of mocking provider internals.
  • Assert AsyncValue states directly for async providers.
  • Dispose containers in tests.

Common Pitfalls

  • Do not call ref.watch inside callbacks; use ref.read there.
  • Do not skip ProviderScope at the app root.
  • Do not use StateProvider for large feature state.
  • Do not put business logic in widgets.
  • Do not rebuild the whole tree when a single field changes; use select.
  • Do not model async loading manually when FutureProvider or AsyncNotifier fits.
  • Do not forget provider overrides for tests and previews.

What To Prefer In Answers

When writing code or advising on design:

  • show the smallest working provider first
  • mention whether ProviderScope is required
  • mention whether the provider should be autoDispose or cached
  • mention whether a family is needed for arguments
  • include test override notes when dependencies are external
  • keep examples aligned with the current Riverpod docs and Flutter integration patterns
  • if code generation is involved, prefer matching riverpod_annotation / riverpod_generator versions from the same 3.x release line

Minimal Reference Checklist

  • ProviderScope = app root setup
  • ref.watch = rebuild on change
  • ref.read = imperative access
  • select = narrower rebuilds
  • autoDispose = short-lived state
  • family = parameterized provider
  • ProviderContainer = test/headless container
자주 묻는 질문

어떤 Riverpod 버전을 다루나요?

스킬은 현재 안정 버전 계열이 Riverpod 3.x라고 밝힙니다.

Flutter용으로 따로 패키지가 필요한가요?

Flutter 앱에는 flutter_riverpod을 쓰며, 이것이 핵심 패키지를 함께 가져옵니다.

Riverpod이 최선이 아닌 경우는 언제인가요?

스킬은 작은 로컬 토글에는 간단한 위젯만으로 충분할 수 있고, 이벤트가 많은 로직에는 Bloc이 더 맞을 수 있다고 말합니다.

상세 정보

작성자의 원본 설명

Use when working with Flutter Riverpod state management. Covers providers, consumers, refs, containers, overrides, async state, code generation, testing, and safe defaults.

repo: andrewyng/context-hub

인기도

GitHub 스타
14k
순위
#11270
라이선스
MIT
업데이트
2026. 5. 31.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬