5

I am currently working on Flutter Firebase to save the details of the users that are signing up for the app.

What I've done is that the user are able to sign up with their email and password. But what I would like to know is how do I add other user information such as Address to be saved so that the users will be able to see it when I am retrieving it from Firebase to the app.

What I've done :

AuthResult user = await 
FirebaseAuth.instance.createUserWithEmailAndPassword(email: _email,password:_password);

This saves the user email and password into the database.

I've tried the solution on : Flutter user registration with Firebase: Add extra user information (age, username)

What I've tried to do :

Firestore.instance.collection('users').document().setData({ 'userid': 
user.uid, 'username': _address });

And I seem to get errors on that Firestore is an undefined name along with the uid isn't defined for the class 'AuthResult' . Am I missing some import files?

I've only imported :

import 'package:firebase_auth/firebase_auth.dart';

Also, I know I have to create a table called user to allow the data to be saved in but which one do I use? The Cloud Firestore or the Realtime Database?

Thanks for all the help.

Spizzle
  • 95
  • 2
  • 8
  • Not the solution to the question you're asking, but please use `document(user.uid)` instead of just `document()`. What you now have generates a document ID, while it's idiomatic (and much easier) to use the UID as the key in a `users` collection. – Frank van Puffelen Oct 27 '19 at 14:49

1 Answers1

0

You have a lot of questions hidden in a single question. I'll try to address as many as I can below, but please try to stick to a single question in the future.


Recommending one database over the other is off-topic on Stack Overflow. But I'd recommend reading the Firebase documentation on it here.

Since you started with Cloud Firestore, let's focus on that.


You'll need to import the plugin for Firestore, just like you've done with the plugin with Authentication. So something like:

import 'package:cloud_firestore/cloud_firestore.dart';

As you've discovered, there is no AuthResult.uid property. In such cases, I recommend browsing the reference documentation for the plugin, which makes it fairly easy to see that AuthResult.user is probably the path to go.

So something like:

AuthResult result = await 
FirebaseAuth.instance.createUserWithEmailAndPassword(email: _email,password:_password);
User user = result.user;

Not the solution to the question you're asking, but please use document(user.uid) instead of just document(). What you now have generates a document ID, while it's idiomatic (and much easier) to use the UID as the key in a users collection.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807