marcojakob / dart-event-bus

An Event Bus using Dart Streams for decoupling applications
MIT License
755 stars 82 forks source link

Flutter: listening callback not be called #19

Closed Julyyq closed 4 years ago

Julyyq commented 5 years ago

In my "HomePage" initState function, I place the following code for listening to NewOrderEvent:

import '../eventbus/eventbus.dart';
.....
@override
void initState() {
  super.initState();
  eventBus.on<NewOrderEvent>().listen((event) {
    print("event fired: $event");
  });
}

These code works fine and in main.dart file, I invoke eventBus.fire(new NewOrderEvent("some data"); when my app receive message from Firebase Cloud Message, the eventBus.fire function is indeed be invoked, but the listen callback function not be called.

This is my "eventbus.dart" file content:

import 'package:event_bus/event_bus.dart';

EventBus eventBus = new EventBus();

class NewOrderEvent {
  Map order;

  NewOrderEvent(this.order);
}

I print the firing eventBus object and listening eventBus object: screenshot 2018-12-09 17 47 57

They are indeed the same object.

BTW, the following are property and methods of the eventBus object: screenshot 2018-12-09 17 53 36

Julyyq commented 5 years ago

I solve the problem, seems that there is a bug of attaching Map data to the event.

screenshot 2018-12-09 18 25 52

rravithejareddy commented 5 years ago

Is it solved? I need a sample example in flutter using EventBus in different widget class (Other than main), that would be a great for flutter people.

marcojakob commented 5 years ago

Reopening this because there seems to be an issue (also see #16), although I don't quite understand it yet. If someone could clarify, it would be great.

Julyyq commented 5 years ago

@marcojakob My problem is that passing Map type data to the listener, the listener function cannot be called.

JordyBaylac commented 5 years ago

Reopening this because there seems to be an issue (also see #16), although I don't quite understand it yet. If someone could clarify, it would be great.

@marcojakob , Why is it opened if it is not clear that #16 has same issue than this?

marcojakob commented 5 years ago

@JordyBaylac Do you also have an issue with event bus and flutter?

rio45ka commented 5 years ago

Is it solved? I need a sample example in flutter using EventBus in different widget class (Other than main), that would be a great for flutter people.

@marcojakob can you give example?

JordyBaylac commented 4 years ago

@marcojakob no I am not having any issue so far.

rravithejareddy commented 4 years ago

Is it solved? I need a sample example in flutter using EventBus in different widget class (Other than main), that would be a great for flutter people.

@marcojakob can you give example?

No actually, i misunderstood flutter flow that's why i needed event-bus then, now we are just following simple pattern, event bus is needed for particular scenarios, at present we are not using it. Thanks for your support.

marcojakob commented 4 years ago

I'll close this since the problem seems to not be the event bus but something else.

uchiha-itachi95 commented 3 years ago

I am also facing the same issue. I am also firing one event on message from Firebase. The listener is another screen which is pushed over the screen which is actually sending the event.

Strange enough, if I send event from screen A to Screen B (screen B is a BottomNavigationBarItem) it works. But if screen B is another screen which is pushed onto screen A, it does not work.

Above the author said it does not support Map data. But I am sending basic int data. That also seems not to work.

marcojakob commented 3 years ago

@uchiha-itachi95 Please check that you are using the same instance of your EventBus.

yahu1031 commented 9 months ago

@marcojakob I am facing the same issue with the latest version. The data is being intermittently gathered. I have a similar scenario: I have an event bus listener on page A (where it works fine). And now I have 1-2 pages stacked or pushed over page A. And I have an same instance event bus listener which listens to the same event in page B(which gets data intermittently). Hope this will get a fix or a solution(work around).