aloisdeniel / built_bloc

Generate the BLoC pattern boilerplate.
MIT License
51 stars 5 forks source link

Generated code for Bind should have an option to ignore errors #6

Open jaumard opened 5 years ago

jaumard commented 5 years ago

Basically here is what's generated when using @Bind

@override
  void subscribeParent(LoginPhoneBloc value) {
    this._parent = value;
    this._parent._phoneNumber.listen(value._managePhoneNumber);
  }

Problem is that if later you're doing something like

_phoneNumber.addError('Wrong phone!!!');

You get a crash, but it's a wanted error that will be show on UI side, I don't want it to spread.

The right generated code should be:

this._parent._phoneNumber.listen(value._managePhoneNumber, onError: (_) {});

By default I think @Bind should swallow errors, as in bloc you mainly addError because you want it. but an additional ignoreError boolean field to override that behavior can be useful (maybe ^^)