riverpod-migration
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRiverpod — Migration guides
Riverpod — 迁移指南
Instructions
使用说明
This skill points to detailed migration guides for different scenarios. Use the reference file that matches your case.
本技能提供不同场景下的详细迁移指南,请根据你的情况选择对应的参考文件。
When to use which guide
不同场景对应的指南选择
| Scenario | Reference |
|---|---|
| From StateNotifier to Notifier / AsyncNotifier | migration_from_state_notifier.md |
| From ChangeNotifier to AsyncNotifier | migration_from_change_notifier.md |
| Upgrade 0.13.x → 0.14.x (StateNotifierProvider syntax, watch(provider) vs provider.state) | migration_0_13_0_14.md |
| Upgrade 0.14.x → 1.0 (ScopedReader → WidgetRef, useProvider → ref.watch, StateProvider) | migration_0_14_1_0.md |
For Riverpod 2.0 → 3.0 see the riverpod-3-0-migration skill.
| 场景 | 参考文件 |
|---|---|
| 从StateNotifier 迁移至Notifier / AsyncNotifier | migration_from_state_notifier.md |
| 从ChangeNotifier 迁移至AsyncNotifier | migration_from_change_notifier.md |
| 从0.13.x升级至0.14.x(StateNotifierProvider语法、watch(provider)与provider.state的区别) | migration_0_13_0_14.md |
| 从0.14.x升级至1.0(ScopedReader替换为WidgetRef、useProvider替换为ref.watch、StateProvider相关变更) | migration_0_14_1_0.md |
关于Riverpod 2.0 升级至3.0的内容,请查看riverpod-3-0-migration技能。
Common themes
通用要点
- StateNotifier → Notifier/AsyncNotifier: Put init logic in ; use
buildinstead of overloadingref.onDispose; nodispose—use cancellation (e.g. Completer or HTTP cancel token). Consumers stay the same (ref.watch, methods on notifier).mounted - ChangeNotifier → AsyncNotifier: Replace /
isLoading/manual try-catch withhasError; singleAsyncValue; mutations by reassigningstate.state - CLI: For 0.14 and 1.0 upgrades you can run then
dart pub global activate riverpod_cliin the project (do not upgrade Riverpod manually first; the tool will suggest version and changes).riverpod migrate
Open the relevant reference file for step-by-step instructions and code examples.
- StateNotifier → Notifier/AsyncNotifier: 将初始化逻辑放在方法中;使用
build替代重写ref.onDispose方法;不再有dispose属性,需使用取消机制(例如Completer或HTTP取消令牌)。消费者端代码保持不变(ref.watch、notifier上的方法)。mounted - ChangeNotifier → AsyncNotifier: 使用替代
AsyncValue/isLoading以及手动try-catch;仅保留单个hasError;通过重新赋值state实现状态变更。state - CLI工具: 针对0.14到1.0的升级,你可以先运行,然后在项目中执行
dart pub global activate riverpod_cli(不要手动先升级Riverpod;工具会建议合适的版本及变更内容)。riverpod migrate
请打开对应的参考文件查看分步说明及代码示例。