Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add linkStyle argument to HtmlRichTextParser and HtmlOldParser #70

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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