riverpod-migration

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Riverpod — 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

不同场景对应的指南选择

ScenarioReference
From StateNotifier to Notifier / AsyncNotifiermigration_from_state_notifier.md
From ChangeNotifier to AsyncNotifiermigration_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 / AsyncNotifiermigration_from_state_notifier.md
从ChangeNotifier 迁移至AsyncNotifiermigration_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
    build
    ; use
    ref.onDispose
    instead of overloading
    dispose
    ; no
    mounted
    —use cancellation (e.g. Completer or HTTP cancel token). Consumers stay the same (ref.watch, methods on notifier).
  • ChangeNotifier → AsyncNotifier: Replace
    isLoading
    /
    hasError
    /manual try-catch with
    AsyncValue
    ; single
    state
    ; mutations by reassigning
    state
    .
  • CLI: For 0.14 and 1.0 upgrades you can run
    dart pub global activate riverpod_cli
    then
    riverpod migrate
    in the project (do not upgrade Riverpod manually first; the tool will suggest version and changes).
Open the relevant reference file for step-by-step instructions and code examples.
  • StateNotifier → Notifier/AsyncNotifier: 将初始化逻辑放在
    build
    方法中;使用
    ref.onDispose
    替代重写
    dispose
    方法;不再有
    mounted
    属性,需使用取消机制(例如Completer或HTTP取消令牌)。消费者端代码保持不变(ref.watch、notifier上的方法)。
  • ChangeNotifier → AsyncNotifier: 使用
    AsyncValue
    替代
    isLoading
    /
    hasError
    以及手动try-catch;仅保留单个
    state
    ;通过重新赋值
    state
    实现状态变更。
  • CLI工具: 针对0.14到1.0的升级,你可以先运行
    dart pub global activate riverpod_cli
    ,然后在项目中执行
    riverpod migrate
    (不要手动先升级Riverpod;工具会建议合适的版本及变更内容)。
请打开对应的参考文件查看分步说明及代码示例。