Skip to content

Commit

Permalink
update to v1.1.4, fix issue #13 and #16
Browse files Browse the repository at this point in the history
  • Loading branch information
asjqkkkk committed May 4, 2020
1 parent bc48cb3 commit dbfe04f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#### [1.1.4] - fix issue [#13](https://github.com/asjqkkkk/markdown_widget/issues/13) and [#16](https://github.com/asjqkkkk/markdown_widget/issues/16), deprecated `compute` function

#### [1.1.3] - add `loadingWidget` before data is ready, improve performance in the first rendering

#### [1.1.2] - support dark mode now! see issue [#12](https://github.com/asjqkkkk/markdown_widget/issues/12)
Expand Down
24 changes: 13 additions & 11 deletions lib/markdown_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ class _MarkdownWidgetState extends State<MarkdownWidget> {

@override
void initState() {
initialState();
updateState();
super.initState();
}

///at the first time, we need to use isolate to create data to avoid UI thread stuck
@Deprecated('Not working on phone now')
void initialState() {
_MarkdownData _markdownData = _MarkdownData(
data: widget.data,
Expand All @@ -68,6 +69,7 @@ class _MarkdownWidgetState extends State<MarkdownWidget> {

///use a new isolate to create [MarkdownGenerator]
compute(buildMarkdownGenerator, _markdownData).then((value) {
print('value:$value');
markdownGenerator = value;
tocList.addAll(markdownGenerator.tocList);
widgets.addAll(markdownGenerator.widgets);
Expand All @@ -91,16 +93,6 @@ class _MarkdownWidgetState extends State<MarkdownWidget> {
itemPositionsListener.itemPositions.addListener(indexListener);
}

Future<MarkdownGenerator> buildMarkdownGenerator(
_MarkdownData markdownData) async {
return MarkdownGenerator(
data: markdownData.data,
widgetConfig: markdownData.widgetConfig,
styleConfig: markdownData.styleConfig,
childMargin: markdownData.childMargin,
);
}

void clearState() {
tocList.clear();
widgets.clear();
Expand Down Expand Up @@ -185,3 +177,13 @@ class _MarkdownData {
_MarkdownData(
{this.data, this.widgetConfig, this.styleConfig, this.childMargin});
}

MarkdownGenerator buildMarkdownGenerator(
_MarkdownData markdownData) {
return MarkdownGenerator(
data: markdownData.data,
widgetConfig: markdownData.widgetConfig,
styleConfig: markdownData.styleConfig,
childMargin: markdownData.childMargin,
);
}
8 changes: 4 additions & 4 deletions lib/tags/table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class MTable {
}

void _buildTh(m.Node node, List<m.Element> thList) {
if (node != null && node is m.Element && !node.isEmpty) {
if (node != null && node is m.Element) {
if (node.tag == th) thList.add(node);
List.generate(node.children.length,
List.generate(node?.children?.length ?? 0,
(index) => _buildTh(node.children[index], thList));
}
}
Expand Down Expand Up @@ -108,9 +108,9 @@ class MTable {
}

void _buildTd(m.Node node, List<m.Element> tdList) {
if (node != null && node is m.Element && !node.isEmpty) {
if (node != null && node is m.Element) {
if (node.tag == td) tdList.add(node);
List.generate(node.children.length,
List.generate(node.children?.length ?? 0,
(index) => _buildTd(node.children[index], tdList));
}
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: markdown_widget
description: A new markdown package. It supports TOC function, HTML video and img tag,and it works well on both the web and mobile
version: 1.1.3
version: 1.1.4
verified publisher:
- agedchen@gmail.com
homepage: https://github.com/asjqkkkk/markdown_widget
Expand Down

0 comments on commit dbfe04f

Please sign in to comment.