Skip to content

Commit

Permalink
add linkStyle argument to HtmlRichTextParser and HtmlOldParser
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepighetti committed Mar 5, 2019
1 parent d354604 commit 40a0b4a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
7 changes: 7 additions & 0 deletions lib/flutter_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class Html extends StatelessWidget {
this.customRender,
this.blockSpacing = 14.0,
this.useRichText = false,
this.linkStyle = const TextStyle(
decoration: TextDecoration.underline,
color: Colors.blueAccent,
decorationColor: Colors.blueAccent),
}) : super(key: key);

final String data;
Expand All @@ -25,6 +29,7 @@ class Html extends StatelessWidget {
final bool renderNewlines;
final double blockSpacing;
final bool useRichText;
final TextStyle linkStyle;

/// Either return a custom widget for specific node types or return null to
/// fallback to the default rendering.
Expand All @@ -46,6 +51,7 @@ class Html extends StatelessWidget {
onLinkTap: onLinkTap,
renderNewlines: renderNewlines,
html: data,
linkStyle: linkStyle,
)
: HtmlOldParser(
width: width,
Expand All @@ -54,6 +60,7 @@ class Html extends StatelessWidget {
customRender: customRender,
html: data,
blockSpacing: blockSpacing,
linkStyle: linkStyle,
),
),
);
Expand Down
23 changes: 13 additions & 10 deletions lib/html_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ class HtmlRichTextParser extends StatelessWidget {
this.onLinkTap,
this.renderNewlines = false,
this.html,
this.linkStyle = const TextStyle(
decoration: TextDecoration.underline,
color: Colors.blueAccent,
decorationColor: Colors.blueAccent),
});

final double indentSize = 10.0;
Expand All @@ -152,6 +156,7 @@ class HtmlRichTextParser extends StatelessWidget {
final onLinkTap;
final bool renderNewlines;
final String html;
final TextStyle linkStyle;

// style elements set a default style
// for all child nodes
Expand Down Expand Up @@ -497,13 +502,9 @@ class HtmlRichTextParser extends StatelessWidget {
nextContext.parentElement = linkContainer;
nextContext.rootWidgetList.add(linkContainer);
} else {
TextStyle linkStyle = parseContext.childStyle.merge(TextStyle(
decoration: TextDecoration.underline,
color: Colors.blueAccent,
decorationColor: Colors.blueAccent,
));
TextStyle _linkStyle = parseContext.childStyle.merge(linkStyle);
LinkTextSpan span = LinkTextSpan(
style: linkStyle,
style: _linkStyle,
url: url,
onLinkTap: onLinkTap,
children: <TextSpan>[],
Expand Down Expand Up @@ -812,6 +813,10 @@ class HtmlOldParser extends StatelessWidget {
this.customRender,
this.blockSpacing,
this.html,
this.linkStyle = const TextStyle(
decoration: TextDecoration.underline,
color: Colors.blueAccent,
decorationColor: Colors.blueAccent),
});

final double width;
Expand All @@ -820,6 +825,7 @@ class HtmlOldParser extends StatelessWidget {
final CustomRender customRender;
final double blockSpacing;
final String html;
final TextStyle linkStyle;

static const _supportedElements = [
"a",
Expand Down Expand Up @@ -940,10 +946,7 @@ class HtmlOldParser extends StatelessWidget {
child: Wrap(
children: _parseNodeList(node.nodes),
),
style: const TextStyle(
decoration: TextDecoration.underline,
color: Colors.blueAccent,
decorationColor: Colors.blueAccent),
style: linkStyle,
),
onTap: () {
if (node.attributes.containsKey('href') && onLinkTap != null) {
Expand Down

0 comments on commit 40a0b4a

Please sign in to comment.