Skip to content

Commit eeb1dc3

Browse files
Merge branch 'master' into add-offset-tags-support
2 parents ec962c6 + ce387e0 commit eeb1dc3

File tree

9 files changed

+803
-274
lines changed

9 files changed

+803
-274
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ obj/
9999
.idea/sqlDataSources.xml
100100
.idea/dynamic.xml
101101
.idea/uiDesigner.xml
102+
.idea/markdown-navigator.xml
103+
.idea/markdown-navigator/
102104

103105
# OS-specific files
104106
.DS_Store

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [0.9.0] - January 31, 2019:
2+
3+
* Adds an alternate `RichText` parser and `useRichText` parameter. ([#37](https://github.com/Sub6Resources/flutter_html/pull/37))
4+
15
## [0.8.2] - November 1, 2018:
26

37
* Removes debug prints.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Matthew Whitaker
3+
Copyright (c) 2019 Matthew Whitaker
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A Flutter widget for rendering static html tags as Flutter widgets. (Will render
88
Add the following to your `pubspec.yaml` file:
99

1010
dependencies:
11-
flutter_html: ^0.8.2
11+
flutter_html: ^0.9.0
1212

1313
## Currently Supported HTML Tags:
1414
`a`, `abbr`, `acronym`, `address`, `article`, `aside`, `b`, `bdi`, `bdo`, `big`, `blockquote`, `body`, `br`, `caption`, `cite`, `code`, `data`, `dd`, `del`, `dfn`, `div`, `dl`, `dt`, `em`, `figcaption`, `figure`, `footer`, `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `header`, `hr`, `i`, `img`, `ins`, `kbd`, `li`, `main`, `mark`, `nav`, `noscript`, `ol`, `p`, `pre`, `q`, `rp`, `rt`, `ruby`, `s`, `samp`, `section`, `small`, `span`, `strike`, `strong`, `table`, `tbody`, `td`, `template`, `tfoot`, `th`, `thead`, `time`, `tr`, `tt`, `u`, `ul`, `var`
@@ -72,4 +72,10 @@ until official support is added.
7272
}
7373
}
7474
},
75-
)
75+
)
76+
77+
## `useRichText` parameter
78+
79+
This package has a known issue where text does not wrap correctly. Setting `useRichText` to true fixes the issue
80+
by using an alternate parser. The alternate parser, however, does not support the `customRender` callback, and several elements
81+
supported by the default parser are not supported by the alternate parser.

lib/flutter_html.dart

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ class Html extends StatelessWidget {
99
@required this.data,
1010
this.padding,
1111
this.backgroundColor,
12-
this.defaultTextStyle = const TextStyle(color: Colors.black),
12+
this.defaultTextStyle,
1313
this.onLinkTap,
1414
this.renderNewlines = false,
1515
this.customRender,
1616
this.blockSpacing,
17+
this.useRichText = false,
1718
}) : super(key: key);
1819

1920
final String data;
@@ -23,6 +24,7 @@ class Html extends StatelessWidget {
2324
final OnLinkTap onLinkTap;
2425
final bool renderNewlines;
2526
final double blockSpacing;
27+
final bool useRichText;
2628

2729
/// Either return a custom widget for specific node types or return null to
2830
/// fallback to the default rendering.
@@ -37,17 +39,22 @@ class Html extends StatelessWidget {
3739
color: backgroundColor,
3840
width: width,
3941
child: DefaultTextStyle.merge(
40-
style: defaultTextStyle,
41-
child: Wrap(
42-
alignment: WrapAlignment.start,
43-
children: HtmlParser(
44-
width: width,
45-
onLinkTap: onLinkTap,
46-
renderNewlines: renderNewlines,
47-
customRender: customRender,
48-
blockSpacing: blockSpacing
49-
).parse(data),
50-
),
42+
style: defaultTextStyle ?? DefaultTextStyle.of(context).style,
43+
child: (useRichText)
44+
? HtmlRichTextParser(
45+
width: width,
46+
onLinkTap: onLinkTap,
47+
renderNewlines: renderNewlines,
48+
html: data,
49+
)
50+
: HtmlOldParser(
51+
width: width,
52+
onLinkTap: onLinkTap,
53+
renderNewlines: renderNewlines,
54+
customRender: customRender,
55+
html: data,
56+
blockSpacing: blockSpacing,
57+
),
5158
),
5259
);
5360
}

0 commit comments

Comments
 (0)