Flutter-Bounty-Hunters / follow_the_leader

MIT License
13 stars 5 forks source link

Follow within Scrollables (Resolves #17) #18

Closed matthew-carroll closed 1 year ago

matthew-carroll commented 1 year ago

Follow within Scrollables (Resolves #17)

We were basing Followers on the local offset of the Leader, which worked in demos where the Leader happened to base its position on the screen's (0,0). However, when a Leader is positioned in a Scrollable, the Leader's origin changes relative to the screen, which resulted in bad Follower positions.

This PR uses LeaderLink.offset, which is the Leader's global offset, instead of LeaderLink.leader.offset, which is local.

Maybe we should also define LeaderLink.leader.globalOffset and get rid of LeaderLink.offset.

This PR makes the Follower widget as large as possible, even when its child is smaller. This is because I discovered that hit testing will only be attempted when the cursor is over the area that Flutter thinks the Follower occupies. So the follower content can be small, but the Follower widget needs to take up all possible area where the Leader might reside. This change also required that we pass the child RenderObject to the boundary and aligner, instead of the Follower, because the Follower's size no longer reflects the size of its content.

This PR also adds a few tests, though there are many situations that remain untested.