Skip to content

Make auto_scroll follow in-place content growth#6637

Open
FeodorFitsner wants to merge 1 commit into
flet-0.86from
auto-scroll-follow-content-growth
Open

Make auto_scroll follow in-place content growth#6637
FeodorFitsner wants to merge 1 commit into
flet-0.86from
auto-scroll-follow-content-growth

Conversation

@FeodorFitsner

@FeodorFitsner FeodorFitsner commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Problem

auto_scroll only scrolls to the end from inside ScrollableControl.build(). That fires when the scrollable rebuilds — e.g. a child is added — but not when existing content grows in place, such as text streamed into an existing child. So an auto-scrolling chat/log follows new messages but falls behind while a single message grows.

Changes

packages/flet/lib/src/controls/scrollable_control.dart:

  • Add a NotificationListener<ScrollMetricsNotification> that re-pins to the end whenever the scroll extent grows, even when this widget doesn't rebuild.
  • Track the user's scroll position (via a ScrollController listener, 40px threshold): pinning pauses while the user has scrolled away from the end and resumes when they scroll back — so it never yanks a user who scrolled up to read history.
  • New auto_scroll_animation property (duration + curve). Defaults to the historical 1s ease; set a duration of 0 for an instant jump (nice for fast, token-by-token streaming).

sdk/python/packages/flet/src/flet/controls/scrollable_control.py:

  • Add the auto_scroll_animation: Optional[AnimationValue] property and update the auto_scroll docs.

Notes

  • Backward compatible: existing auto_scroll=True users keep the 1s ease behavior and additionally gain in-place-growth following.
  • flutter analyze on the changed control: no issues.

Summary by Sourcery

Enhance scrollable controls so auto-scroll stays pinned to the end while content grows in place and remains user-friendly when the user scrolls away.

New Features:

  • Add continuous auto-scroll behavior that follows scroll extent growth, not just rebuilds, while respecting when the user scrolls away from the end.
  • Introduce an auto_scroll_animation option to configure the duration and curve of auto-scroll, including support for instant jumps.

Documentation:

  • Expand ScrollableControl.auto_scroll documentation to cover in-place content growth and user scroll behavior.
  • Document the new auto_scroll_animation property and its accepted formats and defaults.

auto_scroll only scrolled to the end from ScrollableControl.build(), so it
followed added children but not content that grows *in place* (e.g. text
streamed into an existing child) — that never rebuilds the scrollable.

- Add a ScrollMetricsNotification listener that re-pins to the end whenever the
  scroll extent grows, even without a rebuild.
- Track the user's position; suspend pinning while they've scrolled away from
  the end and resume when they return.
- Add an auto_scroll_animation property (duration + curve) to control the
  scroll; defaults to the historical 1s ease, set duration 0 for an instant
  jump.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: a86251e
Status: ✅  Deploy successful!
Preview URL: https://176d86a3.flet-website-v2.pages.dev
Branch Preview URL: https://auto-scroll-follow-content-g.flet-website-v2.pages.dev

View logs

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.

1 participant