Open giorgio79 opened 2 years ago
Seems to be working in our example app. Make sure to use a 'constant' anchorKey
.
new Scaffold(
floatingActionButton: FloatingActionButton(
child: Icon(Icons.arrow_downward),
onPressed: () {
final anchorContext = AnchorKey.forId(staticKey, "bottom")?.currentContext;
if (anchorContext != null) {
Scrollable.ensureVisible(anchorContext);
}
},
),
body: SingleChildScrollView(
child: Html(
anchorKey: staticKey,
data: htmlData,
),
),
);
And that you update to release 3.0.0-alpha.5.
Thx Eric! Ah, the example is really nice, we need to promote the link in the package description https://github.com/Sub6Resources/flutter_html/blob/master/example/lib/main.dart
I noticed the scrolling only works if the anchor is a "p" tag. Tried replacing it with a "span" or an "a" tag but no candy.
PS also tried switching to div, and plain div works, but as soon as I add inline it stops working
<div id='bottom' style='color:orange; display:inline'>HEHEHE</div>
Ah yeah it might currently only work on block elements. Let me see if that is something I can fix.
How are you getting along Eric? I was looking at the code
https://github.com/Sub6Resources/flutter_html/search?q=AnchorKey
and notice AnchorKey is added replaced_element.dart "Wrap" and layout_element.dart "ExpansionTile". Would it be adding a similar line of code to the rest of the elements created by flutter_html?
Yes, basically we have to add the key to all such elements but it's not quite so simple I think (without deep diving yet) because inline elements don't have a WidgetSpan and InlineSpan doesn't have a key to attach to I think.
Happy to chip in 20 bucks :)
Hello,
I am trying to scroll to an HTML anchor with AnchorKey.forId call but it does not seem to be working. I am providing a full example here with a large HTML that has a "TESTING" a anchor towards the end. When clicking on the Button to scroll nothing happens. Can you please help?