romain.gyh b46a6aa9a6
Fix directional focus in nested scrollables with different axis (#172875)
<!--
Thanks for filing a pull request!
Reviewers are typically assigned within a week of filing a request.
To learn more about code review, see our documentation on Tree Hygiene:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
-->

Related issue : #172854 
Fixes #160431

This PR fixes the focus when navigating with keyboard arrows or TV
remote d-pad in a nested lists with different axis and a fixed focusable
at the top.
It's a common setup for apps that deal with images or videos.

The problem is that when the vertical scrollbar has scrolled and you
want to scroll back to the top without the mouse, only using keyboard up
arrow to jump from widgets to widgets in the list until reaching the
top, the fixed top focusable widget wrongly takes the focus instead of
letting the vertical scrollable scroll.

I think the video bellow explain the problem better.

| Before this PR | After this PR |
|--------|--------|
|
https://github.com/user-attachments/assets/54160e0c-abe5-4181-9aea-8351ce5f35b5
|
https://github.com/user-attachments/assets/eee32175-37eb-44a6-a7c2-a751fc82d592
|

Note that I had to edit two existing tests because they were failing
with my edits. However, I think these tests were testing a bad behavior.

For example here is the visualization of the `Focus traversal inside a
vertical scrollable scrolls to stay visible` test case before this PR :


https://github.com/user-attachments/assets/be843ae8-a0df-411e-971c-3bf763c457e0


Test was green bug the focus behavior is weird. When pressing arrow down
from item 3 we would expect a scroll and item 4 to be focused, here it's
footer that is focused and when we press arrow down again item 5 is
focused and item 4 is skipped.

Here is the behavior after this PR and the test edited :



https://github.com/user-attachments/assets/b90757a8-042d-4d53-b7e6-19b9141cc83f


## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
2025-08-12 22:07:18 +00:00
..
2024-12-19 20:06:21 +00:00
2024-12-19 20:06:21 +00:00
2024-12-19 20:06:21 +00:00