skip to Main Content

I’m developing a login page on flutter using Firebase and I can’t display the popups for wrong email/password, What am i doing wrong? I’ve read and watch many videos and answers here but it seems i can’t find a proper solution for my problem if anyone could help me i would appreciate it. If someone can show me what am i doing wrong i ve uploaded 2 slides of my code

slide1
slide2

3

Answers


  1. You have to pass BuildContext on button press.

    ElevatedButton(onPressed: () => signInUser(context), child: Text('Sign In'));
    

    Method code

    void signInUser(BuildContext context) { //get BuildContext
        showDialog(
          context: context, // use here
          builder: (context) => Center(
            child: CircularProgressIndicator(),
          ),
        );
    
        //same as other dialogs
        showDialog(
          context: context, // use here
          builder: (context) => Center(
            child: CircularProgressIndicator(),
          ),
        );
        // call your other dialog like this
         wrongEmail(context);
      }
    
    
    
    
    void wrongEmail(BuildContext context) {
        showDialog(
          context: context,
          builder: (context) => AlertDialog(
            title: Text('Error'),
            content: Text('Wrong Email'),
          ),
        );
      }
    
    Login or Signup to reply.
  2. Future.delayed(
                    Duration.zero,
                    () {
                      ///add code of show dialog here....
                    },
                  );
    

    You can use Future.delayed like this.

    Login or Signup to reply.
  3. Problem seems in your first slide, you are directly showing loading dialog from async gap. try moving our showLoading also in seperate method. This will fix the warning. For example

      void login() async {
        showLoading();
        try{
          final response = await firbaseLogin()
          hideLoading()
          showSuccess()
        } catch(e){
          hideLoading()
          showError()
        }
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search