I am currently using flutter_widget_from_html_core
to view html string that we got from our cms. Additionally, am using url_launcher
package to open an anchor tag href.
Current approach:
HtmlWidget(
html ?? '',
customStylesBuilder: (element) {
},
customWidgetBuilder: (element) {
},
onErrorBuilder: (context, element, error) {
},
onTapUrl: (url) async {
return launchUrlString(url);
},
)
How can i imitate the HTML's way of jumping to a specific part of a page based on the id of the element
something like in this example here
In the
HtmlWidgetState
class, there is a method namedscrollToAnchor
which allows scrolling to a specific element identified by itsid
, see pub.dev.If you want to scroll as soon as the page is opened, you might consider initiating the scrolling action in the
initState
method. Here's how you could implement it:Note that there can be issues, especially if the HTML content is extensive. In such cases, the
HtmlWidget
might perform asynchronous rendering, which means immediate scrolling might not be feasible. However, this general approach should give you a good starting point.