Skip to content

Commit 8fbe713

Browse files
committed
Fix onLinkTap in selectable mode not working due to null anchorKey
1 parent 79cdfdf commit 8fbe713

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/flutter_html.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ class SelectableHtml extends StatelessWidget {
213213
214214
SelectableHtml({
215215
Key? key,
216+
GlobalKey? anchorKey,
216217
required this.data,
217218
this.onLinkTap,
218219
this.onAnchorTap,
@@ -221,10 +222,13 @@ class SelectableHtml extends StatelessWidget {
221222
this.style = const {},
222223
this.tagsList = const [],
223224
}) : document = null,
225+
assert(data != null),
226+
_anchorKey = anchorKey ?? GlobalKey(),
224227
super(key: key);
225228

226229
SelectableHtml.fromDom({
227230
Key? key,
231+
GlobalKey? anchorKey,
228232
required this.document,
229233
this.onLinkTap,
230234
this.onAnchorTap,
@@ -233,8 +237,13 @@ class SelectableHtml extends StatelessWidget {
233237
this.style = const {},
234238
this.tagsList = const [],
235239
}) : data = null,
240+
assert(document != null),
241+
_anchorKey = anchorKey ?? GlobalKey(),
236242
super(key: key);
237243

244+
/// A unique key for this Html widget to ensure uniqueness of anchors
245+
final GlobalKey _anchorKey;
246+
238247
/// The HTML data passed to the widget as a String
239248
final String? data;
240249

@@ -271,7 +280,7 @@ class SelectableHtml extends StatelessWidget {
271280
return Container(
272281
width: width,
273282
child: HtmlParser(
274-
key: null,
283+
key: _anchorKey,
275284
htmlData: doc,
276285
onLinkTap: onLinkTap,
277286
onAnchorTap: onAnchorTap,

0 commit comments

Comments
 (0)