Thank you for writing the event_bus_plus library.
I am using event_bus_plus on windows.
I used the fluent component library and built a FluentApp.
There is a NavigationPaneItem.
For example, switching pages to PageA
within NavigationPaneItem
I have defined EventListener in the page class:
class _CustomerManagePageState extends State<CustomerManagePage>
late var customerViewEventListener;
//............ignore some other code
}
I init Event Listener in initState().
@override
void initState() {
super.initState();
initEventListeners();
}
void initEventListeners() {
logger().info("initEventListeners");
customerViewEventListener =
eventBus().on<CustomerViewEvent>().listen((event) {
// pop dialog
});
}
I cancel Event Listener in dispose().
@override
void deactivate() {
customerViewEventListener.cancel();
super.deactivate();
}
When I click a button, the button publishes an Event and a dialog pops up.
Button(
onPressed: () {
eventBus().fire(CustomerViewEvent.popCreateDialog());
}
)
But when I switch PageB
, and then switch back to PageA
, the dialog will still appear.
Event will not be published repeatedly. But EventListener cancellation is useless.
By the way, I use GetIt to manage EventBus(), , is it related to this?
getIt.registerSingleton<EventBus>(EventBus());
Expected result:
When switching from PageB
to PageA
, the popup dialog will not pop up