create_flutter_provider_app icon indicating copy to clipboard operation
create_flutter_provider_app copied to clipboard

No user creation

Open psimondk opened this issue 3 years ago • 2 comments

Updated: Used the instructions and inserted the following in register_screen in order to patch the app so that user creation actually lead to a user record in the database. Alas it throws the dreaded "Error: Could not find the correct provider ..." - So what is the deal with register_screen?

FirestoreDatabase firestoreDatabase = Provider.of<FirestoreDatabase>(context);

psimondk avatar Sep 11 '20 13:09 psimondk

Patched:

if (userModel == null) { _scaffoldKey.currentState.showSnackBar(SnackBar( content: Text(AppLocalizations.of(context) .translate("loginTxtErrorSignIn")), )); } else { // Patched to allow user creation in DB // Terrible hack - but life is too short for providers and other gluecode final FirestoreDatabase firestoreDatabase = FirestoreDatabase(uid: userModel.uid); firestoreDatabase.setUser(userModel); } }

And in firetore_database.dart:

//Method to create/update userModel Future<void> setUser(UserModel user) async => await _firestoreService.setData( path: FirestorePath.user(uid), data: user.toMap(), );

And in user_model.dart: `class UserModel { String uid; String email; String displayName; String phoneNumber; String photoUrl;

UserModel( {this.uid, this.email, this.displayName, this.phoneNumber, this.photoUrl});

Map<String, dynamic> toMap() { return {'uid': uid, 'email': email}; } }`

Apart from this - great template !!!

psimondk avatar Sep 12 '20 08:09 psimondk

Hi @psimondk ,

Thanks for the info. Been cought up with project work. Yes, we need to capture the user into Firebase. Thanks for the sharing of tips - yup, adding the UserModel and the services will resolve the issue. 👍

KenAragorn avatar Sep 28 '20 06:09 KenAragorn