[two_dimensional_scrollables] Fixes TreeView crash when empty or last node collapsed (#11622) This PR provides a robust fix for a crash in TreeView and resolves a regression introduced by a previous partial fix in PR #9103. Previous attempts to fix the "empty tree" crash (shrinking to 0 rows) by moving _updateScrollBounds to the end of layout introduced a subtle inconsistency. When a node collapse triggered a scroll correction, the visible row range was recalculated after the layout loop had finished. This resulted in the paint phase attempting to access children that were never built, causing a null dereference (as seen in the Expand then collapse with offscreen nodes (top) test). * _updateVerticalScrollBounds is now called before the child layout loop. This ensures that any vertical scroll corrections (e.g., clamping when content shrinks) happen first, so the layout loop builds exactly the rows that will be visible. * Accurate Extent Calculation: Updated _updateScrollBounds to calculate the vertical scroll extent using the total height of all rows in _rowMetrics (via _rowMetrics.last.trailingOffset). This provides a consistent maxScrollExtent and correctly handles the "empty tree" state. * Correct Horizontal Bounds: Updated the horizontal extent calculation to use absolute content-relative positions, ensuring correct scroll bounds when scrolling horizontally. Fixes https://github.com/flutter/flutter/issues/164981 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
This repo is a companion repo to the main flutter repo. It contains the source code for Flutter's first-party packages (i.e., packages developed by the core Flutter team). Check the packages directory to see all packages.
These packages are also available on pub.
Please file any issues, bugs, or feature requests in the main flutter repo. Issues pertaining to this repository are labeled “package”.
If you wish to contribute a new package to the Flutter ecosystem, please see the documentation for developing packages. You can store your package source code in any GitHub repository (the present repo is only intended for packages developed by the core Flutter team). Once your package is ready you can publish to the pub repository.
If you wish to contribute a change to any of the existing packages in this repo, please review our contribution guide, and send a pull request.
These are the packages hosted in this repository: