title: flutter_bloc (emit was called after an event handler completed normally
body: <p>So, I was working with Django rest framework creating my APIs and all.
  And i wanted to check if I can get the response from the backend.
  So, I was able to get the response. But I saw some issues on the debug console. Please help me figure out the problem.
  This is what I received on the Debug Console.</p>
  <pre><code>Restarted application in 1,314ms.
  I/flutter ( 1751): {&quot;token&quot;:&quot;0d15f2d45f11869174395d623c066080bd2ade52&quot;}
  E/flutter ( 1751): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 'package:bloc/src/bloc.dart': Failed assertion: line 232 pos 7: '!_isCompleted':
  E/flutter ( 1751):
  E/flutter ( 1751):
  E/flutter ( 1751): emit was called after an event handler completed normally.
  E/flutter ( 1751): This is usually due to an unawaited future in an event handler.
  E/flutter ( 1751): Please make sure to await all asynchronous operations with event handlers
  E/flutter ( 1751): and use emit.isDone after asynchronous operations before calling emit() to
  E/flutter ( 1751): ensure the event handler has not completed.
  E/flutter ( 1751):
  E/flutter ( 1751):   **BAD**
  E/flutter ( 1751):   on&lt;Event&gt;((event, emit) {
  E/flutter ( 1751):     future.whenComplete(() =&gt; emit(...));
  E/flutter ( 1751):   });
  E/flutter ( 1751):
  E/flutter ( 1751):   **GOOD**
  E/flutter ( 1751):   on&lt;Event&gt;((event, emit) async {
  E/flutter ( 1751):     await future.whenComplete(() =&gt; emit(...));
  E/flutter ( 1751):   });
  E/flutter ( 1751):
  E/flutter ( 1751): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)
  E/flutter ( 1751): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
  E/flutter ( 1751): #2      _Emitter.call
  E/flutter ( 1751): #3      new LoginFormBloc.&lt;anonymous closure&gt;.&lt;anonymous closure&gt;
  E/flutter ( 1751): &lt;asynchronous suspension&gt;
  E/flutter ( 1751):
  Reloaded 1 of 746 libraries in 1,055ms.
  </code></pre>
  <p>Here's my source code:</p>
  <p><strong>login_form_event.dart</strong></p>
  <pre class="lang-dart prettyprint-override"><code>part of 'login_form_bloc.dart';
  
  @freezed
  class LoginFormEvent with _$LoginFormEvent {
    const factory LoginFormEvent.emailChanged(String emailStr) = _EmailChanged;
    const factory LoginFormEvent.passwordChanged(String passwordStr) =
        _PasswordChanged;
    const factory LoginFormEvent.loggedIn() = _LoggedIn;
  }
  </code></pre>
  <p><strong>login_form_state.dart</strong></p>
  <pre class="lang-dart prettyprint-override"><code>part of 'login_form_bloc.dart';
  
  @freezed
  class LoginFormState with _$LoginFormState {
    const factory LoginFormState({
      required EmailAddress emailAddress,
      required Password password,
      required bool isSubmitting,
      required bool showErrorMessages,
      required Option&lt;Either&lt;AuthFailure, TokenValue&gt;&gt; authFailureOrSuccessOption,
    }) = _LoginFormState;
  
    factory LoginFormState.initial() =&gt; LoginFormState(
          emailAddress: EmailAddress(''),
          password: Password(''),
          isSubmitting: false,
          showErrorMessages: false,
          authFailureOrSuccessOption: none(),
        );
  }
  </code></pre>
  <p><strong>login_form_bloc.dart</strong></p>
  <pre class="lang-dart prettyprint-override"><code>class LoginFormBloc extends Bloc&lt;LoginFormEvent, LoginFormState&gt; {
    LoginFormBloc(this._getAuthInfo) : super(LoginFormState.initial()) {
      on&lt;LoginFormEvent&gt;(
        (event, emit) {
          event.map(
            emailChanged: (e) {
              emit(
                state.copyWith(
                  emailAddress: EmailAddress(e.emailStr),
                  authFailureOrSuccessOption: none(),
                ),
              );
            },
            passwordChanged: (e) {
              emit(
                state.copyWith(
                  password: Password(e.passwordStr),
                  authFailureOrSuccessOption: none(),
                ),
              );
            },
            loggedIn: (e) async {
              final isEmailValid = state.emailAddress.value.isRight();
              final isPasswordValid = state.password.value.isRight();
  
              Either&lt;AuthFailure, TokenValue&gt;? loginFailureOrSuccess;
  
              if (isEmailValid &amp;&amp; isPasswordValid) {
                emit(
                  state.copyWith(
                    isSubmitting: true,
                    authFailureOrSuccessOption: none(),
                  ),
                );
                loginFailureOrSuccess = await _getAuthInfo(
                  Params(
                    emailAddress: state.emailAddress,
                    password: state.password,
                  ),
                );
              }
  
           //The error is pointed to this emit below
              emit(
                state.copyWith(
                  isSubmitting: false,
                  showErrorMessages: true,
                  authFailureOrSuccessOption: optionOf(loginFailureOrSuccess),
                ),
              );
            },
          );
        },
      );
    }
    final GetAuthToken _getAuthInfo;
  }
  </code></pre>
  <p>The error is pointed on 2nd emit inside loggedIn event handler.</p>