Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
9001b264
Commit
9001b264
authored
Mar 10, 2016
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Markdown is now correctly updated when config changes
parent
b0542344
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
5 deletions
+54
-5
markdown_raw.dart
packages/flutter_markdown/lib/src/markdown_raw.dart
+23
-5
flutter_markdown_test.dart
packages/flutter_markdown/test/flutter_markdown_test.dart
+31
-0
No files found.
packages/flutter_markdown/lib/src/markdown_raw.dart
View file @
9001b264
...
@@ -129,10 +129,29 @@ class _MarkdownBodyRawState extends State<MarkdownBodyRaw> {
...
@@ -129,10 +129,29 @@ class _MarkdownBodyRawState extends State<MarkdownBodyRaw> {
void
initState
()
{
void
initState
()
{
super
.
initState
();
super
.
initState
();
_buildMarkdownCache
();
}
void
dispose
()
{
_linkHandler
.
dispose
();
super
.
dispose
();
}
void
didUpdateConfig
(
MarkdownBodyRaw
oldConfig
)
{
super
.
didUpdateConfig
(
oldConfig
);
if
(
oldConfig
.
data
!=
config
.
data
||
oldConfig
.
markdownStyle
!=
config
.
markdownStyle
||
oldConfig
.
syntaxHighlighter
!=
config
.
syntaxHighlighter
||
oldConfig
.
onTapLink
!=
config
.
onTapLink
)
_buildMarkdownCache
();
}
void
_buildMarkdownCache
()
{
MarkdownStyleRaw
markdownStyle
=
config
.
markdownStyle
??
config
.
createDefaultStyle
(
context
);
MarkdownStyleRaw
markdownStyle
=
config
.
markdownStyle
??
config
.
createDefaultStyle
(
context
);
SyntaxHighlighter
syntaxHighlighter
=
config
.
syntaxHighlighter
??
new
_DefaultSyntaxHighlighter
(
markdownStyle
.
code
);
SyntaxHighlighter
syntaxHighlighter
=
config
.
syntaxHighlighter
??
new
_DefaultSyntaxHighlighter
(
markdownStyle
.
code
);
_linkHandler
?.
dispose
();
_linkHandler
=
new
_LinkHandler
(
config
.
onTapLink
);
_linkHandler
=
new
_LinkHandler
(
config
.
onTapLink
);
// TODO: This can be optimized by doing the split and removing \r at the same time
// TODO: This can be optimized by doing the split and removing \r at the same time
...
@@ -143,11 +162,6 @@ class _MarkdownBodyRawState extends State<MarkdownBodyRaw> {
...
@@ -143,11 +162,6 @@ class _MarkdownBodyRawState extends State<MarkdownBodyRaw> {
_cachedBlocks
=
renderer
.
render
(
document
.
parseLines
(
lines
),
markdownStyle
,
syntaxHighlighter
,
_linkHandler
);
_cachedBlocks
=
renderer
.
render
(
document
.
parseLines
(
lines
),
markdownStyle
,
syntaxHighlighter
,
_linkHandler
);
}
}
void
dispose
()
{
_linkHandler
.
dispose
();
super
.
dispose
();
}
List
<
_Block
>
_cachedBlocks
;
List
<
_Block
>
_cachedBlocks
;
_LinkHandler
_linkHandler
;
_LinkHandler
_linkHandler
;
...
@@ -162,6 +176,10 @@ class _MarkdownBodyRawState extends State<MarkdownBodyRaw> {
...
@@ -162,6 +176,10 @@ class _MarkdownBodyRawState extends State<MarkdownBodyRaw> {
children:
blocks
children:
blocks
);
);
}
}
void
debugFillDescription
(
List
<
String
>
description
)
{
description
.
add
(
'cached blocks identity:
${_cachedBlocks.hashCode}
'
);
}
}
}
class
_Renderer
implements
md
.
NodeVisitor
{
class
_Renderer
implements
md
.
NodeVisitor
{
...
...
packages/flutter_markdown/test/flutter_markdown_test.dart
View file @
9001b264
...
@@ -94,6 +94,37 @@ void main() {
...
@@ -94,6 +94,37 @@ void main() {
expect
(
span
.
children
[
0
].
recognizer
.
runtimeType
,
equals
(
TapGestureRecognizer
));
expect
(
span
.
children
[
0
].
recognizer
.
runtimeType
,
equals
(
TapGestureRecognizer
));
});
});
});
});
test
(
"Changing config - data"
,
()
{
testWidgets
((
WidgetTester
tester
)
{
tester
.
pumpWidget
(
new
Markdown
(
data:
"Data1"
));
_expectTextStrings
(
_listElements
(
tester
),
<
String
>[
"Data1"
]);
String
stateBefore
=
WidgetFlutterBinding
.
instance
.
renderViewElement
.
toStringDeep
();
tester
.
pumpWidget
(
new
Markdown
(
data:
"Data1"
));
String
stateAfter
=
WidgetFlutterBinding
.
instance
.
renderViewElement
.
toStringDeep
();
expect
(
stateBefore
,
equals
(
stateAfter
));
tester
.
pumpWidget
(
new
Markdown
(
data:
"Data2"
));
_expectTextStrings
(
_listElements
(
tester
),
<
String
>[
"Data2"
]);
});
});
test
(
"Changing config - style"
,
()
{
testWidgets
((
WidgetTester
tester
)
{
ThemeData
theme
=
new
ThemeData
.
light
();
MarkdownStyle
style1
=
new
MarkdownStyle
.
defaultFromTheme
(
theme
);
MarkdownStyle
style2
=
new
MarkdownStyle
.
largeFromTheme
(
theme
);
tester
.
pumpWidget
(
new
Markdown
(
data:
"Test"
,
markdownStyle:
style1
));
String
stateBefore
=
WidgetFlutterBinding
.
instance
.
renderViewElement
.
toStringDeep
();
tester
.
pumpWidget
(
new
Markdown
(
data:
"Test"
,
markdownStyle:
style2
));
String
stateAfter
=
WidgetFlutterBinding
.
instance
.
renderViewElement
.
toStringDeep
();
expect
(
stateBefore
,
isNot
(
stateAfter
));
});
});
}
}
List
<
Element
>
_listElements
(
WidgetTester
tester
)
{
List
<
Element
>
_listElements
(
WidgetTester
tester
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment