title: How to detect an async operation is successful or not in Flutter
body: <p>In my app, after authentication, user can move to the next screen.</p>
  
  <pre><code>              signUpWithEmail().then((user) {
                  Navigator.push(context,
                      MaterialPageRoute(builder: (context) {
                    return HomePage();
                  }));
                }).catchError((error) {
                  print("THE ERROR : $error");
                });
  </code></pre>
  
  <p>Now <code>signUpWithEmail</code> may fail for various reasons like : invalid e-mail, internet connectivity failure and so on. How can I detect those errors and prevent navigation? Here is signUpWithEmail() method:</p>
  
  <pre><code>  Future&lt;FirebaseUser&gt; signUpWithEmail() async {
      String email = emailControlller.text;
      String password = passwordControlller.text;
  
      FirebaseUser user = await FirebaseAuth.instance
          .createUserWithEmailAndPassword(
        email: emailControlller.text,
        password: passwordControlller.text,
      )
          .then((user) {
        // set balance to 0
        Firestore.instance
            .collection("users")
            .document(user.uid)
            .setData({"cash": 0});
      }).catchError((e) =&gt; print("error : $e"));
  
      return user;
    }
  </code></pre>