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?
There is an issue about it in the flutter_bloc repo:
https://github.com/felangel/bloc/issues/1641
The issue is on the todo list.
You may fix your yaml to force the previous version, using single quotes and removing the "^" or any other symbols. Delete your ~/.pub-cache/...
folder and your pubspec.lock
file, run flutter packages get
again and be happy.
Note that the pub-cache folder is shared among all your projects, so you may try to delete only the specific package inside it.
You can investigate transitive dependencies using flutter packages pub deps
to see the flutter_bloc
dependencies and delete them too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With