^0.13.0 to ^0.14.0
With the release of the version 0.14.0
of Riverpod, the syntax for using StateNotifierProvider changed
(see https://github.com/rrousselGit/river_pod/issues/341 for the explanation).
For the entire article, consider the following StateNotifier:
#
The changesStateNotifierProvider takes an extra generic parameter, which should be the type of the state of your StateNotifier.
Before:
After:
to obtain the StateNotifier, you should now read
myProvider.notifier
instead of justmyProvider
:After:
to listen to the state of the StateNotifier, you should now read
myProvider
instead ofmyProvider.state
:Before:
After:
#
Using the migration tool to automatically upgrade your projects to the new syntaxWith the version 0.14.0 came the release of a command line tool for Riverpod, which can help you migrate your projects.
#
Installing the command lineTo install the migration tool, do:
You should now be able to do:
#
UsageNow that the command line is installed, we can start using it.
- First, open the project you want to migrate in your terminal.
- Do not upgrade Riverpod.
The migration tool will upgrade the version of Riverpod for you. - Make sure that your project does not contain errors.
- Execute:
The tool will then analyse your project and suggest changes. For example you may see:
To accept the change, simply press y. Otherwise to reject it, press n.