riverpod
riverpod copied to clipboard
Running riverpod migrate suggests added "WidgetRef ref" to initState
Describe the bug When running riverpod migrate on my project, riverpod recommended passing WidgetRef ref into a stateful widget's initState method.
To Reproduce Run riverpod migrate
<Please add a small sample to that can be executed to reproduce the problem. As a general rule, 100 lines is the maximum>
Expected behavior
Shouldn't recommend this. I think it only happens when I am calling a method in initState that also uses the old context.read
so riverpod suggests passing the WidgetRef into that method.
This is potentially fixable, but it is hard, because if one function needs the parameter (_initDataAndStartRoutine) then all functions that call that function also need to get the WidgetRef so it can pass it down. To fix this we would need to identify methods in StatefulWidgets as different than other methods / functions, and not needing the parameter forwarding. It is possible, but will take some time.
@TimWhiting If it's that big of investment I would vote it just gets put in the documentation that this might happen. It took very little time to correct, and it was pretty easy to understand what it was trying to do.
The migration tool handled 98% of the code migration which is amazing.
Not sure if you were the main developer that worked on this or not but thank you for this tool!
@TimWhiting What exactly is the difficulty? I'm not certain I see the issue here
To begin with, State
methods should not need to receive the ref as parameter since it's available as a State property.
I'll close this. I have no plan to fix the remaining bugs for the migration tool as it's been quite a while now since the breaking change happened.