Skip to content

Commit 24bd197

Browse files
authored
Merge pull request #699 from DFelten/feature/option-to-overwrite-anchor-links
Add possibility to overwrite anchor links
2 parents 8d2e91b + cda0a72 commit 24bd197

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/flutter_html.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class Html extends StatelessWidget {
5252
GlobalKey? anchorKey,
5353
required this.data,
5454
this.onLinkTap,
55+
this.onAnchorTap,
5556
this.customRender = const {},
5657
this.customImageRenders = const {},
5758
this.onCssParseError,
@@ -72,6 +73,7 @@ class Html extends StatelessWidget {
7273
GlobalKey? anchorKey,
7374
@required this.document,
7475
this.onLinkTap,
76+
this.onAnchorTap,
7577
this.customRender = const {},
7678
this.customImageRenders = const {},
7779
this.onCssParseError,
@@ -99,6 +101,10 @@ class Html extends StatelessWidget {
99101
/// A function that defines what to do when a link is tapped
100102
final OnTap? onLinkTap;
101103

104+
/// A function that defines what to do when an anchor link is tapped. When this value is set,
105+
/// the default anchor behaviour is overwritten.
106+
final OnTap? onAnchorTap;
107+
102108
/// An API that allows you to customize the entire process of image rendering.
103109
/// See the README for more details.
104110
final Map<ImageSourceMatcher, ImageRender> customImageRenders;
@@ -154,6 +160,7 @@ class Html extends StatelessWidget {
154160
key: _anchorKey,
155161
htmlData: doc,
156162
onLinkTap: onLinkTap,
163+
onAnchorTap: onAnchorTap,
157164
onImageTap: onImageTap,
158165
onCssParseError: onCssParseError,
159166
onImageError: onImageError,

lib/html_parser.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class HtmlParser extends StatelessWidget {
4444
final Key? key;
4545
final dom.Document htmlData;
4646
final OnTap? onLinkTap;
47+
final OnTap? onAnchorTap;
4748
final OnTap? onImageTap;
4849
final OnCssParseError? onCssParseError;
4950
final ImageErrorListener? onImageError;
@@ -62,6 +63,7 @@ class HtmlParser extends StatelessWidget {
6263
required this.key,
6364
required this.htmlData,
6465
required this.onLinkTap,
66+
required this.onAnchorTap,
6567
required this.onImageTap,
6668
required this.onCssParseError,
6769
required this.onImageError,
@@ -73,7 +75,12 @@ class HtmlParser extends StatelessWidget {
7375
required this.imageRenders,
7476
required this.tagsList,
7577
required this.navigationDelegateForIframe,
76-
}): this._onAnchorTap = key != null ? _handleAnchorTap(key, onLinkTap): null, super(key: key);
78+
}) : this._onAnchorTap = onAnchorTap != null
79+
? onAnchorTap
80+
: key != null
81+
? _handleAnchorTap(key, onLinkTap)
82+
: null,
83+
super(key: key);
7784

7885
@override
7986
Widget build(BuildContext context) {

0 commit comments

Comments
 (0)