Home > Blockchain >  How to fix login issue? Flutter - Firebase
How to fix login issue? Flutter - Firebase

Time:09-24

Here is what I'm doing in my code.

ReusableButton(
          title: "Login",
          color: Colors.white,
          onPress: () async {
            try {
              final user = await _auth.signInWithEmailAndPassword(
                email: myEmailController.text,
                password: myPasswordController.text,
              );
              if (user != null) {
                await Navigator.pushNamed(context, AllTasks.id);
              }
            } catch (e) {
              String newString = e.toString().split("]").removeLast();
              setState(() {
                showDialog(
                    context: context,
                    builder: (value) => AlertDialog(
                          title: Text(
                            "Wrong Information",
                            style: kNormalTextStyle,
                          ),
                          content: Text(
                            newString,
                          ),
                          actions: [
                            FlatButton(
                                onPressed: () {
                                  Navigator.of(value).pop();
                                },
                                child: Text(
                                  "Close",
                                  style: kNormalTextStyle,
                                ))
                          ],
                        ));
              });
            }
          },
        ),

I'm trying to login and after that pushin the page to another page. However this login part is a little bit slow so I get an error like this:

enter image description here

I'm assuming this is about the connection speed with firebase but is there a solution to solve this? Btw, when I reload the code, it starts working.

Here is my AllTasks code block:

https://github.com/sonelektrikci/task_manager_app_flutter/blob/main/task_management_app_flutter/lib/screens/all_tasks.dart

I'm pushing the page to here when user logs in.

CodePudding user response:

This is most likely causing your issue:

 .where('email', isEqualTo: loggedInUser!.email)

How are you asserting that the user is indeed logged in and promising your compiler that an email is retrievable? This is the explanation of your error. Refactor your code, in a way to not make it into this block, unless loggedInUser is not null.

  • Related