In my flutter app, I use flutter_bloc for state management.
The bloc
in question uses a repository
. The repository
subscribes to a websocket, and new data is added to a stream.
Problem: My bloc listens to the stream:
InvestmentClubBloc({
required this.investmentClubRepository
}) : super(InvestmentClubLoading()) {
onChangeSubscription = investmentClubRepository.onNewMessage.listen(
(event) {
emit(NewMessageState(event); // <-- The member "emit" can only be used within 'package:bloc/src/bloc.dart' or in test
},
);
}
The problem is that emit
does not work (I get the warning "The member "emit" can only be used within 'package:bloc/src/bloc.dart' or in test")
How can bloc listen to a stream and emit new states depending on stream events?
flutter_bloc
version do you use? – Uneven