KenAragorn / create_flutter_provider_app

A boilerplate project created in Flutter using Provider and Firebase.
MIT License
400 stars 117 forks source link

Question: Access Firestore from Register while trying to register. #12

Closed fhidal01 closed 3 years ago

fhidal01 commented 3 years ago

I am very new to flutter so Im still trying to wrap my head around how this project is structured and understand how data is flowing. But what I am trying to do is when a new user try's to register an account I want to first query Firestore to see if they have been invited before allowing registration to happen.

My first guess was to simply use Provider of to gain access to the FirestoreDatabase service inside the register_screen.dart file like so:

Widget _buildForm(BuildContext context) { final authProvider = Provider.of<AuthProvider>(context); final firestoreDatabase = Provider.of<FirestoreDatabase>(context, listen: false);

but got and error saying: Could not find the correct Provider<FirestoreDatabase>

I believe this has something to do with the widget tree hierarchy and how the FirestoreDatabase is not above the register page but im not sure. Any suggestions?

Also a related question I have is FirestoreDatabase does not extend ChangeNotifier so how are we even able to use something like

Provider.of<FirestoreDatabase>(context, listen: false);

when FirestoreDatabase is not a real provider, it doesn't notify any changes? Can any regular class be pulled in with Provider.of ??