how to fix flutter blocConsumer state receiver null error

274 Views Asked by At

hi everyone i'm following reso coder serie about DDD and i get error at part eight this is my code:

return BlocConsumer<SignInFormBloc, SignInFormState>(
    builder: (context, state) {},
    listener: (context, state) {});

and this is error :

The following NoSuchMethodError was thrown building BlocConsumer<SignInFormBloc, SignInFormState>:
The getter 'state' was called on null.
Receiver: null
Tried calling: state

and this is sign_in_form_state code :

part of 'sign_in_form_bloc.dart';
@freezed
abstract class SignInFormState with _$SignInFormState {
  const factory SignInFormState({
    @required EmailAddress emailAddress,
    @required Password password,
    @required bool showErrorMessages,
    @required bool isSubmitting,
    @required Option<Either<AuthFailure, Unit>> authFailureOrSuccessOption,
  }) = _SignInFormState;

  factory SignInFormState.initial() => SignInFormState(
        emailAddress: EmailAddress(' '),
        password: Password(' '),
        showErrorMessages: false,
        isSubmitting: false,
        authFailureOrSuccessOption: none(),
      );
}

thanks in advance.

1

There are 1 best solutions below

0
On

this error is coming from the fact i had updated packages version without update my code because with update comme new method and the error of declaration come from sign_in_form_bloc not sign_in_form_state so i have modified this line old line:

SignInFormBloc(SignInFormState initialState, this._authFacade)
      : super(initialState);

new line:

SignInFormBloc(this._authFacade) : super(SignInFormState.initial());

and injection.config.dart was changed from this:

 gh.factory<SignInFormBloc>(() => SignInFormBloc(get<SignInFormState>,get<IAuthFacade>()));

to this:

 gh.factory<SignInFormBloc>(() => SignInFormBloc(get<IAuthFacade>()));