在我的Flutter应用中,我使用flutter_bloc进行状态管理。
所涉及的
问题: 我的bloc监听这个流:
问题在于
bloc如何监听流并根据流事件发出新状态?
所涉及的
bloc
使用一个repository
。该repository
订阅了一个WebSocket,新数据会添加到一个流中。问题: 我的bloc监听这个流:
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
},
);
}
问题在于
emit
无法使用(我收到了警告:"The member "emit" can only be used within 'package:bloc/src/bloc.dart' or in test")。bloc如何监听流并根据流事件发出新状态?
flutter_bloc
版本是哪个? - 聂超群