Skip to content

Commit 2fbf45b

Browse files
Merge pull request Sub6Resources#70 from lukepighetti/modifiable-linkStyle
add linkStyle argument to HtmlRichTextParser and HtmlOldParser
2 parents d354604 + 40a0b4a commit 2fbf45b

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/flutter_html.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class Html extends StatelessWidget {
1515
this.customRender,
1616
this.blockSpacing = 14.0,
1717
this.useRichText = false,
18+
this.linkStyle = const TextStyle(
19+
decoration: TextDecoration.underline,
20+
color: Colors.blueAccent,
21+
decorationColor: Colors.blueAccent),
1822
}) : super(key: key);
1923

2024
final String data;
@@ -25,6 +29,7 @@ class Html extends StatelessWidget {
2529
final bool renderNewlines;
2630
final double blockSpacing;
2731
final bool useRichText;
32+
final TextStyle linkStyle;
2833

2934
/// Either return a custom widget for specific node types or return null to
3035
/// fallback to the default rendering.
@@ -46,6 +51,7 @@ class Html extends StatelessWidget {
4651
onLinkTap: onLinkTap,
4752
renderNewlines: renderNewlines,
4853
html: data,
54+
linkStyle: linkStyle,
4955
)
5056
: HtmlOldParser(
5157
width: width,
@@ -54,6 +60,7 @@ class Html extends StatelessWidget {
5460
customRender: customRender,
5561
html: data,
5662
blockSpacing: blockSpacing,
63+
linkStyle: linkStyle,
5764
),
5865
),
5966
);

lib/html_parser.dart

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ class HtmlRichTextParser extends StatelessWidget {
144144
this.onLinkTap,
145145
this.renderNewlines = false,
146146
this.html,
147+
this.linkStyle = const TextStyle(
148+
decoration: TextDecoration.underline,
149+
color: Colors.blueAccent,
150+
decorationColor: Colors.blueAccent),
147151
});
148152

149153
final double indentSize = 10.0;
@@ -152,6 +156,7 @@ class HtmlRichTextParser extends StatelessWidget {
152156
final onLinkTap;
153157
final bool renderNewlines;
154158
final String html;
159+
final TextStyle linkStyle;
155160

156161
// style elements set a default style
157162
// for all child nodes
@@ -497,13 +502,9 @@ class HtmlRichTextParser extends StatelessWidget {
497502
nextContext.parentElement = linkContainer;
498503
nextContext.rootWidgetList.add(linkContainer);
499504
} else {
500-
TextStyle linkStyle = parseContext.childStyle.merge(TextStyle(
501-
decoration: TextDecoration.underline,
502-
color: Colors.blueAccent,
503-
decorationColor: Colors.blueAccent,
504-
));
505+
TextStyle _linkStyle = parseContext.childStyle.merge(linkStyle);
505506
LinkTextSpan span = LinkTextSpan(
506-
style: linkStyle,
507+
style: _linkStyle,
507508
url: url,
508509
onLinkTap: onLinkTap,
509510
children: <TextSpan>[],
@@ -812,6 +813,10 @@ class HtmlOldParser extends StatelessWidget {
812813
this.customRender,
813814
this.blockSpacing,
814815
this.html,
816+
this.linkStyle = const TextStyle(
817+
decoration: TextDecoration.underline,
818+
color: Colors.blueAccent,
819+
decorationColor: Colors.blueAccent),
815820
});
816821

817822
final double width;
@@ -820,6 +825,7 @@ class HtmlOldParser extends StatelessWidget {
820825
final CustomRender customRender;
821826
final double blockSpacing;
822827
final String html;
828+
final TextStyle linkStyle;
823829

824830
static const _supportedElements = [
825831
"a",
@@ -940,10 +946,7 @@ class HtmlOldParser extends StatelessWidget {
940946
child: Wrap(
941947
children: _parseNodeList(node.nodes),
942948
),
943-
style: const TextStyle(
944-
decoration: TextDecoration.underline,
945-
color: Colors.blueAccent,
946-
decorationColor: Colors.blueAccent),
949+
style: linkStyle,
947950
),
948951
onTap: () {
949952
if (node.attributes.containsKey('href') && onLinkTap != null) {

0 commit comments

Comments
 (0)