I have a class where I have to call an event from my bloc chat_bloc
. Im not able to call the event, since I don't have any context. When I try to add the ChatBloc
to my SocketRepository
im totally lost here.. This is my class:
class SocketRepository {
...
socket.on('receive_message', (jsonData) => {
print('****** receive message called $jsonData'),
// <- I need to call my chat_bloc event, but i don't have any context...
});
..
This is my ChatBloc
which needs 2 parameters (minified important part):
class ChatBloc extends Bloc<ChatEvent, ChatState> {
final DatabaseRepository _databaseRepository;
final SocketRepository _socketRepository;
ChatBloc(_databaseRepository, _socketRepository) : super(ChatInitial()) {
on<LoadChat>((event, emit) async {
My best result i could achieve with the error I have:
class SocketRepository {
late ChatBloc chatbloc;
...
socket.on('receive_message', (jsonData) => {
chatbloc.add(ReceiveMessage()),
..
Unhandled Exception: LateInitializationError: Field 'chatbloc' has not been initialized.
I dont know how to inizialize it in a correct way..