Skip to content

fix SelectableHtml not rebuild when data change #1111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/flutter_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class SelectableHtml extends StatefulWidget {
}

class _SelectableHtmlState extends State<SelectableHtml> {
late final dom.Element documentElement;
late dom.Element documentElement;

@override
void initState() {
Expand All @@ -342,6 +342,16 @@ class _SelectableHtmlState extends State<SelectableHtml> {
? HtmlParser.parseHTML(widget.data!)
: widget.documentElement!;
}
@override
void didUpdateWidget(SelectableHtml oldWidget) {
super.didUpdateWidget(oldWidget);
if ((widget.data != null && oldWidget.data != widget.data) ||
oldWidget.documentElement != widget.documentElement) {
documentElement = widget.data != null
? HtmlParser.parseHTML(widget.data!)
: widget.documentElement!;
}
}

@override
Widget build(BuildContext context) {
Expand Down