You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An event listener added using addEventListener is being called from within a paint loop. I have a button in a rive file which triggers an event. I then have code listening to this. It is failing because the event occurs within the paint loop so I cannot setState
Hi @asaworld the documentation mentions that this may occur. It's a trade-off for having the event immediately available, which is desirable in some situations.
The burden to step around this is on you. We could maybe look into exposing a frame sync listener. Here is an example of how to only call setState when ready to step around this for now:
voidonRiveEvent(RiveEvent event) {
// Access custom properties defined on the eventvar rating = event.properties['rating'] asdouble;
// Schedule the setState for the next frame, as an event can be// triggered during a current frame updateWidgetsBinding.instance.addPostFrameCallback((_) {
setState(() {
ratingValue ='Rating: $rating';
});
});
}
I'll change the issue name to reflect the needed change we can consider for the future.
HayesGordon
changed the title
Event Listener being called in the paint loop
Expose frame synced event callback
Nov 15, 2024
I do expect event listeners to be called outside the build loop and that would probably make a far better default. Calling event handlers inside the paint call is asking for inconsistent rendering or controller updates mid paint loop. You could add an immediate callback for those who might possibly want it.
Description
An event listener added using addEventListener is being called from within a paint loop. I have a button in a rive file which triggers an event. I then have code listening to this. It is failing because the event occurs within the paint loop so I cannot setState
Steps To Reproduce
void _onAnimationInit(Artboard artboard) {
StateMachineController controller = StateMachineController.fromArtboard(artboard, "Default", onStateChange: _onAnimationStateChange)!;
artboard.addController(controller);
_controller.addEventListener(_onAnimationEvent);
}
Expected behavior
Event listeners should only be called outside the paint loop
Screenshots
Device & Versions (please complete the following information)
Flutter 3.24.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 603104015d (8 days ago) • 2024-10-24 08:01:25 -0700
Engine • revision db49896cf2
Tools • Dart 3.5.4 • DevTools 2.37.3
The text was updated successfully, but these errors were encountered: