title: how can I use Future/Async function in a loop? (dart/flutter)
body: <pre><code>        String random_username ;
          bool available = false;
          int n = 0;
          do{
            random_username = SuperHero.random()+(n.toString());
            n = n+1;
            print(random_username);
            checkUsernameAvailable(random_username).then((value){
              available = value;
            });
          }while(!available);
  </code></pre>
  <p>What I am trying to do is when a new user is registered in Firebase Auth, I want to create a random username for the user, which can be changed later.
  this code should generate a username, check if it is already in firebase database. If no, then leave the loop, else add a suffix number and retry.
  (By mistake I've put the name generator in the loop, so every time it will get a new name, and that's okay for now).
  The function <strong>checkUsernameAvailable</strong> return &quot;true&quot; if there's no match, i.e available. and vice versa.</p>
  <p>The problem is that the loop continues forever. maybe this is due to the async method ,i.e, <strong>checkUsernameAvailable</strong>.
  Please help.</p>