I had a Flutter project with an app already being developed on local, and copied the files to a new folder so I use it as a repository for Git.
After doing the "pubspec get packages" everything is all right except from some lines that are related to Riverpod. If I return to the old folder the exact same code work perfectly finde so I guess I have to do something more. Here there is an example:
final nombreJuegoTextFieldProvider = StateProvider<String>((ref) {
return '';
});
void updateNombreJuegoTextField(BuildContext context, String nombre) {
context.read(nombreJuegoTextFieldProvider).state = nombre;
}
And the problem showed is:
The method 'read' isn't defined for the type 'BuildContext'.
Try correcting the name to the name of an existing method, or defining a method named 'read'.
4
Answers
I just repeated the same process again and everything works, I guess the copy paste I did the first time had an error I don't know.
have you tried
-> deleting .gitignore files
-> Run flutter clean project
or maybe the paths got messed up.
You probably haven’t copied all the files to the new folder. Repeat copying. This should include all directories and files from the previous version.
Then run two commands:
In this example of the code presented, the provider’s state can be accessed using
ref
:context.read
is from Provider packageFor riverpod, you need to use
ref.read