title: How to make widget test wait until Bloc has updated the state?
body: <p>I have a <code>EmailScreen</code> (stateful widget) that has a text input, and a button. The button is only enabled when a valid email is input.</p>
  
  <p>I'm using Bloc, and my screen has <code>InitialEmailState</code> and <code>ValidEmailInputState</code>, and it works fine when I run the app.</p>
  
  <p>In my widget test, the second expectation is failing before bloc has a chance to update the state:</p>
  
  <pre class="lang-dart prettyprint-override"><code>
    testWidgets('when valid email is input, button is enabled', (tester) async {
      const validEmail = 'email@provider.com';
  
      emailBloc.listen((event) {
        print('NEW EVENT: ' + event.toString());
      });
  
      await bootUpWidget(tester, emailScreen);
  
      final BottomButton button = tester.widget(
          find.widgetWithText(BottomButton, 'CONTINUE'));
  
      expect(button.enabled, isFalse);
  
      await tester.enterText(find.byType(TextInputScreen), validEmail);
      await tester.pumpAndSettle();
  
      expect(button.enabled, isTrue);
    });
  </code></pre>
  
  <p>And here's the output I'm getting:</p>
  
  <pre><code>NEW EVENT: InitialEmailState
  ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
  The following TestFailure object was thrown running a test:
    Expected: true
    Actual: &lt;false&gt;
  
  ...
  
  The test description was:
    when valid email is input, button is enabled
  ════════════════════════════════════════════════════════════════════════════════════════════════════
  Test failed. See exception logs above.
  The test description was: when valid email is input, button is enabled
  
  NEW EVENT: InputValidEmailState
  ✖ when valid email is input, button is enabled
  Exited (1)
  </code></pre>
  
  <p>As you can see, it prints the initial state, fails the second expectation, and then prints the expected state.</p>
  
  <p>Thanks in advance :)</p>
  
  <p><strong>== UPDATE ==</strong></p>
  
  <p>We managed to get this to work by adding <code>LiveTestWidgetsFlutterBinding();</code> to the start of our main. But it doesn't feel like a good solution.</p>