I have a bloc that listens to another bloc. After updating flutter_bloc
package to version 6.0.2
, the listener won't call anymore in the initial state.
class BlocA extends Bloc {
final BlocB blocB = ...;
...
blocA.blocB.listen((state) {
DO SOMTTHING...
});
...
}
I found this solution:
class BlocB extends Bloc<..., ...> with BehaviorSubjectBloc {
...
}
mixin BehaviorSubjectBloc<TEvent, TState> on Bloc<TEvent, TState> {
@override
StreamSubscription<TState> listen(
void Function(TState state) onData, {
Function onError,
void Function() onDone,
bool cancelOnError,
}) {
onData(this.state);
return super.listen(
onData,
onError: onError,
onDone: onDone,
cancelOnError: cancelOnError,
);
}
}
I wonder is there any better solution?