Skip to content

Commit 9a43e15

Browse files
committed
Use a global key for internal anchors to ensure uniqueness without causing unneeded rebuilds
1 parent 1d5fdba commit 9a43e15

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ EXTERNAL SOURCES:
2626
SPEC CHECKSUMS:
2727
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
2828
video_player: 9cc823b1d9da7e8427ee591e8438bfbcde500e6e
29-
wakelock: bfc7955c418d0db797614075aabbc58a39ab5107
30-
webview_flutter: d2b4d6c66968ad042ad94cbb791f5b72b4678a96
29+
wakelock: b0843b2479edbf6504d8d262c2959446f35373aa
30+
webview_flutter: 9f491a9b5a66f2573946a389b2677987b0ff8c0b
3131

3232
PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d
3333

lib/flutter_html.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class Html extends StatelessWidget {
4949
this.navigationDelegateForIframe,
5050
}) : document = null,
5151
assert (data != null),
52-
super(key: key ?? UniqueKey());
52+
anchorKey = GlobalKey(),
53+
super(key: key);
5354

5455
Html.fromDom({
5556
Key? key,
@@ -66,7 +67,11 @@ class Html extends StatelessWidget {
6667
this.navigationDelegateForIframe,
6768
}) : data = null,
6869
assert(document != null),
69-
super(key: key ?? UniqueKey());
70+
anchorKey = GlobalKey(),
71+
super(key: key);
72+
73+
/// A unique key for this Html widget to ensure uniqueness of anchors
74+
final Key anchorKey;
7075

7176
/// The HTML data passed to the widget as a String
7277
final String? data;
@@ -119,7 +124,7 @@ class Html extends StatelessWidget {
119124
return Container(
120125
width: width,
121126
child: HtmlParser(
122-
key: key,
127+
key: anchorKey,
123128
htmlData: doc,
124129
onLinkTap: onLinkTap,
125130
onImageTap: onImageTap,

0 commit comments

Comments
 (0)