title: How to check user is logged in or not with phone authentication using firebase in flutter?
body: <p>Here, I'm authenticated through the phone number with OTP code using firebase but 
  after login succeeded, it navigated through home page but when I click on back
  it drags me login Screen.</p>
  
  <p>here, the code I have tried, but it doesn't work</p>
  
  <pre class="lang-dart prettyprint-override"><code> @override
    void initState() {
      super.initState();
     isSignedIn();
    }
  
  
    void isSignedIn() async {
      this.setState(() {
        isLoading = true;
      });
  
    firebaseAuth.currentUser().then((user){
      if(user !=null){
        Navigator.of(context).pushReplacementNamed('/homepage');
      }else{
         verifyPhone();
      }
    });
    this.setState(() {
      isLoading = false;
    });
  
    }
  
  </code></pre>
  
  <p>Method for getting OTP code</p>
  
  <pre><code>Future&lt;void&gt; verifyPhone()async{
      final PhoneCodeAutoRetrievalTimeout autoRetrieval=(String verId){
        this.verificationId=verId;
      };
  
      final PhoneCodeSent smsCodeSent=(String verId, [int forceCodeResend]){
        this.verificationId=verId;
        smsCodeDialog(context).then((value){
          print("Signed in");
        });
      };
  
  
  
      final PhoneVerificationCompleted verificationCompleted = (AuthCredential credential) {
       print("verified");
     };
  
      final PhoneVerificationFailed verfifailed=(AuthException exception){
        print("${exception.message}");
      };
  
      await firebaseAuth.verifyPhoneNumber(
       phoneNumber: this.phoneNo,
       codeAutoRetrievalTimeout: autoRetrieval,
       codeSent: smsCodeSent,
       timeout: const Duration(seconds: 10),
       verificationCompleted: verificationCompleted,
       verificationFailed: verfifailed
      );
    }
  </code></pre>
  
  <p>here the dialog box for sign in  with OTP code</p>
  
  <pre><code>Future&lt;bool&gt; smsCodeDialog(BuildContext context){
      return showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context){
          return new AlertDialog(
            title: Text('Enter sms Code'),
            content: TextField(
              onChanged: (value){
                this.smsCode=value;
              },
            ),
            contentPadding: const EdgeInsets.all(10.0),
            actions: &lt;Widget&gt;[
              new FlatButton(
                child: Text("Done"),
                onPressed: (){
                  firebaseAuth.currentUser().then((user){
                    if(user !=null){
                      Navigator.of(context).pop();
                      Navigator.of(context).pushReplacementNamed('/homepage');
                    }else{
                      Navigator.of(context).pop();
                      signIn();
                    }
                  });
                },
              )
            ],
          );
        }
      );
    }
  </code></pre>
  
  <p>method for Sign in with phone number</p>
  
  <pre><code>signIn()async{
      AuthCredential credential= PhoneAuthProvider.getCredential(
        verificationId: verificationId,
        smsCode: smsCode
      );
      await  firebaseAuth.signInWithCredential(credential).then((user){
         Navigator.of(context).pushReplacementNamed('/homepage');
           print('signed in with phone number successful: user -&gt; $user');
      }).catchError((onError){
        print(onError);
      });
    }
  `
  </code></pre>