ResoCoder / flutter-ddd-firebase-course

https://resocoder.com/flutter-firebase-ddd-course
GNU General Public License v3.0
470 stars 161 forks source link

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

Open Ezirius opened 4 years ago

Ezirius commented 4 years ago

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

rdhillbb commented 4 years ago

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 ?

Ezirius commented 4 years ago

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?

rdhillbb commented 4 years ago

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

Ezirius commented 4 years ago

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."

rdhillbb commented 4 years ago

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

Ezirius commented 4 years ago

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

rdhillbb commented 4 years ago

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

Ezirius commented 4 years ago

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

rdhillbb commented 4 years ago

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.

Ezirius commented 4 years ago

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

rdhillbb commented 4 years ago

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

Ezirius commented 4 years ago

Glad that worked. Thanks for the update.