feat(deps): adopt flutter_riverpod 3 - #13
Conversation
Dependabot's PR bumped the constraint and changed nothing else, so analysis failed with 169 errors across 24 files: StateNotifier resolved to nothing, which made every `state` reference undefined and cascaded into every screen and widget that reads a provider. Riverpod 3 did not delete these APIs. It moved StateNotifier, StateNotifierProvider, StateProvider and ChangeNotifierProvider out of the default export into package:flutter_riverpod/legacy.dart, where they remain supported. The four provider files import from there. theme_provider uses nothing from the main export once the legacy import is added, so it imports only legacy -- otherwise the analyzer reports an unused import, which is what the 84th issue was on the first pass. Deliberately NOT migrating the seven notifiers to Notifier/NotifierProvider in the same change. That is a behavioural rewrite, not a rename: a Notifier returns initial state from build() rather than a constructor, so constructor side effects (AuthNotifier calls checkAuth()) have to be re-homed, and state must not be assigned during build. With two tests in the suite there is no net under that. Recorded in the README as the next step, gated on widget coverage. example/ tracks the same constraint so the workspace resolves as one. Verified: flutter analyze 0 errors and 0 warnings, 83 infos -- exactly the pre-change baseline -- and flutter test 2/2, resolved against flutter_riverpod 3.4.3.
flutter_riverpod >=3.4.1 requires Dart ^3.12.0. CI pins Flutter 3.38.10, which ships Dart 3.10.9, so pub could not resolve it at all: Because escalated depends on flutter_riverpod >=3.4.1 which requires SDK version >=3.12.0 <4.0.0, version solving failed. Raises the package environment to sdk >=3.12.0 / flutter >=3.44.0 (the release that ships Dart 3.12) and moves the CI pin to 3.44.x so it can resolve what the package now declares. example/ tracks both. This narrows the supported Flutter window from >=3.19.0, which is the real cost of this PR. Riverpod 3 raises the floor no matter which 3.x is chosen -- 3.0.0 needs Dart ^3.8.0 and 3.2.0 needs ^3.7.0 -- so the choice is how far, not whether. Taking the current release rather than pinning to an older 3.x keeps dependabot quiet instead of re-proposing 3.4.x indefinitely. Analyzer infos go 83 -> 91. The eight new ones are all use_null_aware_elements, a lint that ships with Dart 3.12; none are errors or warnings and none come from this package's own changes. Verified: flutter analyze 0 errors / 0 warnings, flutter test 2/2, resolved against flutter_riverpod 3.4.3.
|
Pushed a second commit — the first one was not enough, and the reason is worth recording.
So this PR now also raises The trade-off to weighThis narrows the supported Flutter window from Riverpod 3 raises the floor whichever 3.x you pick, so the question is how far, not whether:
Pinning I took the current release on the assumption that keeping the dependency current beats preserving Flutter 3.19–3.43 support for a package whose CI pin was already two years of releases behind. If that support window matters to you, say so and I will switch this to Analyzer infos go 83 → 91; all eight new ones are |
Supersedes #12, which failed CI.
Dependabot's PR bumped the constraint and changed nothing else, so
flutter analyzefailed with 169 errors across 24 files:StateNotifierresolved to nothing, which made everystatereference undefined and cascaded into every screen and widget that reads a provider.Riverpod 3 did not delete these APIs
It moved
StateNotifier,StateNotifierProvider,StateProviderandChangeNotifierProviderout of the default export and intopackage:flutter_riverpod/legacy.dart, where they remain supported. The four provider files now import from there, and the 169 errors go to zero.theme_provider.dartuses nothing from the main export once the legacy import is added, so it imports onlylegacy.dart— otherwise the analyzer reports an unused import. That was the one extra issue on my first pass (84 vs the 83 baseline), now resolved.What I deliberately did not do
I did not migrate the seven notifiers to
Notifier/NotifierProviderin this PR, even though that is the intended destination andStateNotifieris legacy.That is a behavioural rewrite rather than a rename. A
Notifierreturns its initial state frombuild()instead of a constructor, so constructor side effects have to be re-homed —AuthNotifiercallscheckAuth()from its constructor today, andstatecannot be assigned duringbuild(). Getting that subtly wrong changes when state is produced, which is exactly the kind of thing that does not show up in analysis.This package ships two tests. That is not a net you can do a seven-notifier state-management rewrite over. The README now records the migration as the next step, gated on widget coverage first.
If you would rather take the rewrite now and accept the risk, say so and I will do it — I just do not think it should ride along unreviewed inside a dependency bump.
Verification
flutter analyze0 errors, 0 warnings, 83 infos — exactly the pre-change baseline, andflutter test2/2, resolved againstflutter_riverpod 3.4.3(confirmed viaflutter pub deps).example/tracks the same constraint so the workspace resolves as one; without that,pubfails outright.Note this one pins
^3.4.3rather than widening, for the same reasonfile_pickerdid in #10: v2 and v3 need different import lines, so a range spanning both would be a promise the code cannot keep.