flutter-ddd-firebase-course icon indicating copy to clipboard operation
flutter-ddd-firebase-course copied to clipboard

flutter_bloc 6.0.1 (Current Latest) Breaks Constructor "AuthBloc(this._authFacade);"

Open Ezirius opened this issue 4 years ago • 12 comments

Thanks for the awesome tutorials. Please upgrade the project to the latest BLoC package.

Ezirius avatar Aug 01 '20 19:08 Ezirius

Question: I get an error message 'The getter 'showErrorMEssages' was called on null. I got this message once I upgraded. Is this is what you are referring to ?

rdhillbb avatar Aug 01 '20 20:08 rdhillbb

With the following versions in dependencies and dev_dependencies in pubspec.yaml:

dependencies: dartz: ^0.9.1 freezed_annotation: ^0.11.0 flutter_bloc: ^6.0.1

dev_dependencies: build_runner: ^1.10.0 freezed: ^0.11.


I get the following on "AuthBloc(this._authFacade);":

The superclass 'Bloc<AuthBlocEvent, AuthBlocState>' doesn't have a zero argument constructor. Try declaring a zero argument constructor in 'Bloc<AuthBlocEvent, AuthBlocState>', or explicitly invoking a different constructor in 'Bloc<AuthBlocEvent, AuthBlocState>'.dart(no_default_super_constructor)


Remember that you need to add the following override otherwise you will get a "requires the 'non-nullable' language feature to be enabled" error with build_runner:

dependency_overrides: analyzer: ^0.39.14

I presume that there is a bug in analyzer 0.39.15?

Ezirius avatar Aug 01 '20 21:08 Ezirius

I am just not getting it on your comment with related to AuthBoc.

rdhillbb avatar Aug 02 '20 08:08 rdhillbb

In bloc.dart...


The Bloc definition in 4.0.0 is:

abstract class Bloc<Event, State> extends Stream<State> implements Sink<Event> {

...

  /// {@macro bloc}
  Bloc() {
    _state = initialState;
    _bindEventsToStates();
  }

...


The Bloc definition in 6.0.1 is:

abstract class Bloc<Event, State> extends Cubit<State>
    implements EventSink<Event> {
  /// {@macro bloc}
  Bloc(State initialState) : super(initialState) {
    _bindEventsToStates();
  }

...


Therefore you get the compile time error, "The superclass 'Bloc<AuthBlocEvent, AuthBlocState>' doesn't have a zero argument constructor."

Ezirius avatar Aug 02 '20 08:08 Ezirius

I was not clear or I have no clue at all. I am not getting a compile error, i think. It is runtime. If i down grade to flutter_bloc: ^4.0.0 No issue at all.

return Form( autovalidate: state.showErrorMessages, <---- Generates Error. state has a null. ════════ Exception caught by widgets library ═══════════════════════════════════ The following NoSuchMethodError was thrown building BlocBuilder<SignInFormBloc, SignInFormState>(dirty, state: _BlocBuilderBaseState<SignInFormBloc, SignInFormState>#2d670): The getter 'showErrorMessages' was called on null. Receiver: null Tried calling: showErrorMessages

The relevant error-causing widget was BlocConsumer<SignInFormBloc, SignInFormState> package:notes_firebase_ddd_course/…/widgets/sign_in_form.dart:13 When the exception was thrown, this was the stack #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) #1 SignInForm.build. package:notes_firebase_ddd_course/…/widgets/sign_in_form.dart:40 #2 BlocBuilder.build

rdhillbb avatar Aug 02 '20 09:08 rdhillbb

Okay, so there are at least 2 separate issues that need to be solved to upgrade the BLoC library to the latest version

Ezirius avatar Aug 02 '20 09:08 Ezirius

Yes. Does the fix need to be part of Bloc or the application?

rdhillbb avatar Aug 02 '20 09:08 rdhillbb

In the app to accommodate the breaking changes implemented in the BLoC library

Ezirius avatar Aug 02 '20 09:08 Ezirius

I will stay at 4.0.0 until there is a fix. I am working on an APP that stopped working with the New Bloc.

rdhillbb avatar Aug 02 '20 23:08 rdhillbb

@rdhillbb, not BLoC related, but may help in terms of understanding/implementing Clean Architecture and TDD:

Ezirius avatar Aug 09 '20 22:08 Ezirius

All I did was take the finished code and upgraded to 6.0.1. No modifications. I will take your suggestions.

rdhillbb avatar Aug 10 '20 01:08 rdhillbb

Glad that worked. Thanks for the update.

Ezirius avatar Aug 10 '20 06:08 Ezirius