NewsCrawler.org

Migrating 261 handwritten Riverpod providers to @riverpod code generation

手書き Provider 261 件を @riverpod へ全面移行した進め方
Image: zenn.dev

Developers at Japan Trading Card Center migrated all 261 handwritten Riverpod[1] provider declarations in their Flutter app to @riverpod code generation and rewrote 130 classes extending StateNotifier[2], which Riverpod 3 deprecated, into Notifier. The approach was to migrate a small batch first to measure the effort and find the hard spots, then split the work into pull requests that would not conflict with each other. Adding the generator required a Flutter update: the app ran Flutter 3.44 (Dart 3.12), but riverpod_generator 4.0.8 needs analyzer ^13.0.0, only freezed 4.0.0 supports analyzer 13, freezed 4.0.0 needs Dart >=3.13.0, and Dart 3.13 ships with Flutter 3.47.0 and later. The team verified this chain in a worktree with Flutter 3.47.1 in three steps, rejecting the alternative of an older generator because it would have forced a riverpod downgrade and undone the finished Riverpod 3 migration; the reasoning went into an ADR[3], and all 4,414 existing tests passed.

Two trial migrations measured the cost: a plain provider takes four mechanical steps and keeps its generated name, so callers and tests stay unchanged, but the default flips from keepAlive to autoDispose[4] — 115 of 116 plain providers were keepAlive, while 100 of 129 StateNotifierProvider declarations were autoDispose. Migrating StateNotifier is different work: tests must be rewritten because the generated provider's overrideWith replaces only the Notifier factory while build() still runs, and 51 of 109 declarations (47%) needed renames, with 38 private classes made public. Work was split into two phases — 116 plain providers, then 129 StateNotifierProvider and 16 StateProvider declarations — and after document counts drifted between 246 and 262, a small counting script became the single standard. Cross-screen renames went first into a single PR — 86 declarations, 2,193 replacement points, 276 files — after which eight screen PRs, each written by a coding agent, ran in parallel with zero file overlap; the final integration PR into main spanned 744 files and about 30,000 lines, but the 22 child PRs had each been reviewed individually.

Migration PRs were kept strictly behavior-preserving — existing bugs such as missing mounted checks after await were split into separate work — and CI checks, a deliberately planted lint violation and updated CodeRabbit review rules were added to keep the codebase from sliding back. The result: handwritten provider declarations went from 261 to 0, StateNotifier subclasses from 130 to 0, @riverpod declarations reached 284, all 4,887 flutter tests passed, and the Maestro E2E run on an Android emulator passed.

Read the original zenn.dev

Sources

  • Zenn JA

    手書き Provider 261 件を @riverpod へ全面移行した進め方

    11 likes6 bookmarks0 comments

Published: First seen: Читать по-русски

Open as a page