title: Flutter close a Dialog inside a condition
body: <p>I am trying to close a Dialog dynamically.
  What I am actually trying to do is to change the content of the dialog depending on the information I have at the moment.</p>
  
  <p>Starts with loading info and no button and after a few seconds could be an error with the OK button to close the Dialog Box.</p>
  
  <pre><code>class Dialogs{
    loginLoading(BuildContext context, String type, String description){
      var descriptionBody;
  
      if(type == "error"){
        descriptionBody = CircleAvatar(
          radius: 100.0,
          maxRadius: 100.0,
          child: new Icon(Icons.warning),
          backgroundColor: Colors.redAccent,
        );
      } else {
        descriptionBody = new Center(
          child: new CircularProgressIndicator(),
        );
      }
  
      return showDialog(
        context: context,
        barrierDismissible: false,
        builder: (BuildContext context){
          return AlertDialog(
            title: descriptionBody,
            content: SingleChildScrollView(
              child: ListBody(
                children: &lt;Widget&gt;[
                  Center(child: Text(description))
                ],
              ),
            ),
          );
        }
      );
    }
  }
  </code></pre>
  
  <p>So after creating the instance os the dialog and opening it</p>
  
  <pre><code>Dialogs _dialog = new Dialogs();
  _dialog.loginLoading(context, "loading", "loading...");
  
  // Close the dialog code here
  don't know how to do it
  
  // Call again the AlertDialog with different content.
  </code></pre>