daohoangson / flutter_widget_from_html

Flutter package to render html as widgets that supports hyperlink, image, audio, video, iframe and many other tags.
https://pub.dev/packages/flutter_widget_from_html
MIT License
635 stars 235 forks source link

jumpToAnchor(String id) method #1107

Open Maybells opened 10 months ago

Maybells commented 10 months ago

Use case

My current project is using this library to render very long html files (5000+ elements). This works fine when the user is manually scrolling through the page, but is an issue when they click an anchor link. The widget attempts to smoothly scroll to its destination, but the size of the content makes the transition sloppy and slow.

Proposal

I think it would be useful if the HtmlWidget had a jumpToAnchor(String id) method to go along with its scrollToAnchor(String id) method, like how ScrollController has both jumpTo() and animateTo() methods. Alternatively, it could be a setting in the constructor (something like "anchorBehavior: AnchorBehavior.jump" or "animateAnchors: false".

daohoangson commented 10 months ago

The target element might be located beyond the visible area, making it impossible to jump directly (such as when it's in a sliver). That's why scrollToAnchor must works incrementally, gradually bringing the target into view before executing the final scroll action to reach it.