Flutter not inserting new user to Firebase

Viewed 77

in my Flutter project I'm trying to sign up new user via email and password

In firebase console enabled Auth via email and password but new users not inserting

Other data from Cloud Firestore fetching successfully

debug console message:when I click register button afterr filling email and pass I/BiChannelGoogleApi( 7328): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzao@b8e2d46 after this nothing happens:

In my

pubspec.yaml

firebase_auth: ^0.18.3

firebase_core: ^0.5.2

Here my code:

signInSheet(BuildContext context) {
    return showModalBottomSheet(
        context: context,
        builder: (context) {
          return new Container(
            height: 400.0,
            width: 400.0,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(25.0),
                color: Color(0xFF191531)),
            child: Center(
              child: Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: TextField(
                      decoration: InputDecoration(
                          hintText: 'Enter email...',
                          hintStyle: TextStyle(
                            fontWeight: FontWeight.bold,
                            color: Colors.white,
                          )),
                      controller: emailController,
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: TextField(
                      obscureText: true,
                      decoration: InputDecoration(
                          hintText: 'Enter password...',
                          hintStyle: TextStyle(
                            fontWeight: FontWeight.bold,
                            color: Colors.white,
                          )),
                      controller: passwordController,
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: FloatingActionButton(
                        backgroundColor: Colors.redAccent,
                        child:
                            Icon(FontAwesomeIcons.check, color: Colors.white),
                        onPressed: () =>
                            Provider.of<Authentication>(context, listen: false)
                                .createNewAccount(emailController.text,
                                    passwordController.text)
                                .whenComplete(() {
                              if (Provider.of<Authentication>(context,
                                          listen: false)
                                      .getErrorMessage !=
                                  null) {
                                Navigator.pushReplacement(
                                    context,
                                    PageTransition(
                                        child: HomeScreen(),
                                        type: PageTransitionType.leftToRight));
                              } else {
                                Navigator.pushReplacement(
                                    context,
                                    PageTransition(
                                        child: Login(),
                                        type: PageTransitionType.leftToRight));
                              }
                            })),
                  ),
                  Text(
                    Provider.of<Authentication>(context, listen: true)
                        .getErrorMessage,
                    style: TextStyle(
                        color: Colors.white, fontWeight: FontWeight.bold),
                  )
                ],
              ),
            ),
          );
        });
  }
}
1 Answers

not sure what this does

 Provider.of<Authentication>(context, listen: false)
                                .createNewAccount(emailController.text,
                                    passwordController.text)

Anyway what you need is when create user with email and password is successful you need to add entry to firestore

//id obtained from current user instance
User user = FirebaseAuth.instance.currentUser;
 FirebaseFirestore.instance.collection("users").doc(user.id).set(
            {"username": "username, "phoneNo": "phone", "desc": "null","id":user.id});
Related