Skip to content

FIX: More like a workaround for issue https://github.com/woltapp/wolt… #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

rydmike
Copy link

@rydmike rydmike commented Apr 28, 2025

FIX: #374

Summary of my and AI analysis of the Problem

  1. The Error: The assertion !debugNeedsLayout fails within RenderFractionalTranslation.hitTestChildren.
  2. Meaning: This assertion means that Flutter is attempting to perform hit testing (determining which widget is under the pointer) on a RenderFractionalTranslation object while that object has been marked as needing a layout update (markNeedsLayout was called) but before the layout update has actually been performed (performLayout hasn't run yet in the current frame pipeline for this object). This is not allowed because hit testing requires up-to-date layout information (size and position) to work correctly.
  3. The Trigger: The error specifically happens when scrolling the modal sheet content using a mouse wheel.
  4. Likely Cause (Race Condition):
    • A mouse wheel scroll event occurs over the scrollable content (ListView) inside the modal sheet.
    • The Flutter framework starts processing this event. This involves dispatching the pointer event down the widget tree for hit testing to find the target (ListView).
    • Simultaneously (or as part of the event handling), the scroll event likely triggers a ScrollNotification that bubbles up from the ListView.
    • The WoltModalSheet widget listens for these notifications to potentially react to the scroll position (e.g., maybe for subtle animations, overscroll effects, or coordinating with sheet dragging).
    • This notification handler calls setState to update some state related to the sheet's position or appearance.
    • This setState triggers a rebuild. During the build, widgets related to the sheet's positioning (which often involve SlideTransition or other animations internally using FractionalTranslation -> RenderFractionalTranslation) get updated. This marks their corresponding RenderObjects (like RenderFractionalTranslation) as needing layout (markNeedsLayout()).
    • However, the original hit testing process for the mouse wheel event is still ongoing within the same frame. When the hit test reaches the now-dirty RenderFractionalTranslation, the assertion !debugNeedsLayout fails because layout hasn't happened yet for it in this frame.

Workaround fix

To avoid this issue I for now made a workaround I can use temporarily at least. However, a real fix should involve getting rid of any out-of bounds set state calls in relation the used scroll listeners.

The temp fix is a bit of hack, every usage of the Flutter SlideTransition (which under the hood is a FractionalTranslation) was replaced with a simple custom pixel‑based Transform.translate widget called PixelSlideTransition. That completely removes the underlying FractionalTranslation hit‑test logic that was tripping the “!debugNeedsLayout” assertion when we spin the mouse wheel.

I also wrapped our route’s entrance/exit transition in an AbsorbPointer so that no pointer events (incl. wheel scrolls) ever hit the sheet until its first layout is fully finished. Also

throttled our TopBarFlow’s scroll listener to only call setState in the next frame (so we never mark the sheet dirty mid‑hitTest).

All of these changes combined eliminate the debugMode crash we are seeing.

I am going to submit the changes as a PR so you can take a look at them. I don't think it is necessary a good actual actual fix to merge, but I must get rid of the assert now. And will use a temporary fork with this fix in it to do so while waiting for a better actual fix.

You may use the PR as inspiration if you like, but as said I'm not expecting it to be merged, you can of course if you so like, but I think finding and fixing the actual cause would be better.

A proper fix should probably prefer getting rid of all out-of bounds setState calls in relation the used scroll listeners.

I tried the fix with the demo issue and also with the package bundled playground example. Worked for both cases.

@TahaTesser
Copy link
Collaborator

TahaTesser commented Apr 28, 2025

Let's keep this PR only for record as this is mostly AI trying anything that sticks to get rid of the error.

@TahaTesser TahaTesser closed this Apr 28, 2025
@rydmike
Copy link
Author

rydmike commented Apr 28, 2025

Yes, it was only added for visibility/discoverability to what was needed to work around the issue, not intended as a solution.

And I am using it via another branch as a temp workaround until the actual issue is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception is thrown when scrolling a bottom sheet with mouse wheel or mouse drag
2 participants