'State error was called without a registered event handler

This is the code for the event file

import 'package:flutter/foundation.dart';

abstract class AuthEvent {}

class InitEvent extends AuthEvent {}

class SubmitEvent extends AuthEvent {
  final String email;
  final String password;
  SubmitEvent({@required this.email, @required this.password});
}

This is how the InitEvent was called...

    import 'auth_event.dart';
import 'auth_state.dart';

class AuthBloc extends Bloc<AuthEvent, AuthStates> {
  AuthBloc() : super(WaitingAuth());

  Stream<AuthStates> mapEventToState(AuthEvent event) async* {
    yield WaitingAuth();
    switch (event.runtimeType) {
      case InitEvent:
        SharedPreferences prefs = await SharedPreferences.getInstance();
        bool login = prefs.getBool('login');
        if (login == null || !login) {
          prefs.clear();
          yield Initialization();
          break;
        } else {
          String token = prefs.getString('token');
          String tokenJWT = prefs.getString('tokenJWT');
          if (token == null ||
              tokenJWT == null ||
              token.isEmpty ||
              tokenJWT.isEmpty) {
            yield Initialization();
          } else {
            setToken(token);
            setJWTToken(tokenJWT);
            final response = await Api.getAccount();
            if (response is Account) {
              final sensorResponse = await Api.getDevices();
              if (sensorResponse is List<Sensor>) {
                yield SuccessAuth(account: response, sensors: sensorResponse);
              } else {
                yield SuccessAuth(account: response, sensors: []);
              }
            } else {
              yield Initialization();
            }
          }
        }
        break;
      case SubmitEvent:

Login screen snippet for InitEvent

    @override
  void initState() {
    _authBloc = AuthBloc();
    _authBloc.add(InitEvent());
    _passwordFocusNode = FocusNode();
    _emailController = TextEditingController();
    _passController = TextEditingController();
    super.initState();
  }

Then in the login screen, InitEvent was called but there is the error of unregistered handler. I don't know what it means. Any help would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source