Format with dartfmt (#122)
diff --git a/packages/flutter_markdown/assets/logo.png b/packages/flutter_markdown/assets/logo.png
new file mode 100644
index 0000000..00357cb
--- /dev/null
+++ b/packages/flutter_markdown/assets/logo.png
Binary files differ
diff --git a/packages/flutter_markdown/lib/src/builder.dart b/packages/flutter_markdown/lib/src/builder.dart
index 4a912b7..4cdf4a2 100644
--- a/packages/flutter_markdown/lib/src/builder.dart
+++ b/packages/flutter_markdown/lib/src/builder.dart
@@ -43,18 +43,18 @@
/// A collection of widgets that should be placed adjacent to (inline with)
/// other inline elements in the same parent block.
-///
-/// Inline elements can be textual (a/em/strong) represented by [RichText]
+///
+/// Inline elements can be textual (a/em/strong) represented by [RichText]
/// widgets or images (img) represented by [Image.network] widgets.
-///
+///
/// Inline elements can be nested within other inline elements, inheriting their
/// parent's style along with the style of the block they are in.
-///
-/// When laying out inline widgets, first, any adjacent RichText widgets are
+///
+/// When laying out inline widgets, first, any adjacent RichText widgets are
/// merged, then, all inline widgets are enclosed in a parent [Wrap] widget.
class _InlineElement {
_InlineElement(this.tag, {this.style});
-
+
final String tag;
/// Created by merging the style defined for this element's [tag] in the
@@ -84,7 +84,7 @@
/// * [Markdown], which is a widget that parses and displays Markdown.
class MarkdownBuilder implements md.NodeVisitor {
/// Creates an object that builds a [Widget] tree from parsed Markdown.
- MarkdownBuilder({ this.delegate, this.styleSheet, this.imageDirectory });
+ MarkdownBuilder({this.delegate, this.styleSheet, this.imageDirectory});
/// A delegate that controls how link and `pre` elements behave.
final MarkdownBuilderDelegate delegate;
@@ -100,7 +100,6 @@
final List<_InlineElement> _inlines = <_InlineElement>[];
final List<GestureRecognizer> _linkHandlers = <GestureRecognizer>[];
-
/// Returns widgets that display the given Markdown nodes.
///
/// The returned widgets are typically used as children in a [ListView].
@@ -129,12 +128,12 @@
_addParentInlineIfNeeded(_blocks.last.tag);
final TextSpan span = _blocks.last.tag == 'pre'
- ? delegate.formatText(styleSheet, text.text)
- : new TextSpan(
- style: _inlines.last.style,
- text: text.text,
- recognizer: _linkHandlers.isNotEmpty ? _linkHandlers.last : null,
- );
+ ? delegate.formatText(styleSheet, text.text)
+ : new TextSpan(
+ style: _inlines.last.style,
+ text: text.text,
+ recognizer: _linkHandlers.isNotEmpty ? _linkHandlers.last : null,
+ );
_inlines.last.children.add(new RichText(
textScaleFactor: styleSheet.textScaleFactor,
@@ -147,8 +146,7 @@
final String tag = element.tag;
if (_isBlockTag(tag)) {
_addAnonymousBlockIfNeeded(styleSheet.styles[tag]);
- if (_isListTag(tag))
- _listIndents.add(tag);
+ if (_isListTag(tag)) _listIndents.add(tag);
_blocks.add(new _BlockElement(tag));
} else {
_addParentInlineIfNeeded(_blocks.last.tag);
@@ -245,8 +243,7 @@
Widget _buildImage(String src) {
final List<String> parts = src.split('#');
- if (parts.isEmpty)
- return const SizedBox();
+ if (parts.isEmpty) return const SizedBox();
final String path = parts.first;
double width;
@@ -282,10 +279,12 @@
}
}
- Widget _handleDataSchemeUri(Uri uri, final double width, final double height) {
+ Widget _handleDataSchemeUri(
+ Uri uri, final double width, final double height) {
final String mimeType = uri.data.mimeType;
if (mimeType.startsWith('image/')) {
- return new Image.memory(uri.data.contentAsBytes(), width: width, height: height);
+ return new Image.memory(uri.data.contentAsBytes(),
+ width: width, height: height);
} else if (mimeType.startsWith('text/')) {
return new Text(uri.data.contentAsString());
}
@@ -294,12 +293,14 @@
Widget _buildBullet(String listTag) {
if (listTag == 'ul')
- return new Text('•', textAlign: TextAlign.center, style: styleSheet.styles['li']);
+ return new Text('•',
+ textAlign: TextAlign.center, style: styleSheet.styles['li']);
final int index = _blocks.last.nextListIndex;
return new Padding(
padding: const EdgeInsets.only(right: 5.0),
- child: new Text('${index + 1}.', textAlign: TextAlign.right, style: styleSheet.styles['li']),
+ child: new Text('${index + 1}.',
+ textAlign: TextAlign.right, style: styleSheet.styles['li']),
);
}
@@ -328,7 +329,9 @@
final _InlineElement inline = _inlines.single;
if (inline.children.isNotEmpty) {
List<Widget> mergedInlines = _mergeInlineChildren(inline);
- final Wrap wrap = new Wrap(children: mergedInlines);
+ final Wrap wrap = new Wrap(
+ children: mergedInlines,
+ );
_addBlockChild(wrap);
_inlines.clear();
}
@@ -338,7 +341,9 @@
List<Widget> _mergeInlineChildren(_InlineElement inline) {
List<Widget> mergedTexts = <Widget>[];
for (Widget child in inline.children) {
- if (mergedTexts.isNotEmpty && mergedTexts.last is RichText && child is RichText) {
+ if (mergedTexts.isNotEmpty &&
+ mergedTexts.last is RichText &&
+ child is RichText) {
RichText previous = mergedTexts.removeLast();
TextSpan previousTextSpan = previous.text;
List<TextSpan> children = previousTextSpan.children != null
diff --git a/packages/flutter_markdown/lib/src/style_sheet.dart b/packages/flutter_markdown/lib/src/style_sheet.dart
index 6c44b77..2043ae3 100644
--- a/packages/flutter_markdown/lib/src/style_sheet.dart
+++ b/packages/flutter_markdown/lib/src/style_sheet.dart
@@ -28,24 +28,24 @@
this.codeblockPadding,
this.codeblockDecoration,
this.horizontalRuleDecoration,
- this.textScaleFactor = 1.0
+ this.textScaleFactor = 1.0,
}) : _styles = <String, TextStyle>{
- 'a': a,
- 'p': p,
- 'li': p,
- 'code': code,
- 'pre': p,
- 'h1': h1,
- 'h2': h2,
- 'h3': h3,
- 'h4': h4,
- 'h5': h5,
- 'h6': h6,
- 'em': em,
- 'strong': strong,
- 'blockquote': blockquote,
- 'img': img,
- };
+ 'a': a,
+ 'p': p,
+ 'li': p,
+ 'code': code,
+ 'pre': p,
+ 'h1': h1,
+ 'h2': h2,
+ 'h3': h3,
+ 'h4': h4,
+ 'h5': h5,
+ 'h6': h6,
+ 'em': em,
+ 'strong': strong,
+ 'blockquote': blockquote,
+ 'img': img,
+ };
/// Creates a [MarkdownStyleSheet] from the [TextStyle]s in the provided [ThemeData].
factory MarkdownStyleSheet.fromTheme(ThemeData theme) {
@@ -54,10 +54,9 @@
a: const TextStyle(color: Colors.blue),
p: theme.textTheme.body1,
code: new TextStyle(
- color: Colors.grey.shade700,
- fontFamily: "monospace",
- fontSize: theme.textTheme.body1.fontSize * 0.85
- ),
+ color: Colors.grey.shade700,
+ fontFamily: "monospace",
+ fontSize: theme.textTheme.body1.fontSize * 0.85),
h1: theme.textTheme.headline,
h2: theme.textTheme.title,
h3: theme.textTheme.subhead,
@@ -73,16 +72,16 @@
blockquotePadding: 8.0,
blockquoteDecoration: new BoxDecoration(
color: Colors.blue.shade100,
- borderRadius: new BorderRadius.circular(2.0)
+ borderRadius: new BorderRadius.circular(2.0),
),
codeblockPadding: 8.0,
codeblockDecoration: new BoxDecoration(
color: Colors.grey.shade100,
- borderRadius: new BorderRadius.circular(2.0)
+ borderRadius: new BorderRadius.circular(2.0),
),
horizontalRuleDecoration: new BoxDecoration(
border: new Border(
- top: new BorderSide(width: 5.0, color: Colors.grey.shade300)
+ top: new BorderSide(width: 5.0, color: Colors.grey.shade300),
),
),
);
@@ -97,10 +96,9 @@
a: const TextStyle(color: Colors.blue),
p: theme.textTheme.body1,
code: new TextStyle(
- color: Colors.grey.shade700,
- fontFamily: "monospace",
- fontSize: theme.textTheme.body1.fontSize * 0.85
- ),
+ color: Colors.grey.shade700,
+ fontFamily: "monospace",
+ fontSize: theme.textTheme.body1.fontSize * 0.85),
h1: theme.textTheme.display3,
h2: theme.textTheme.display2,
h3: theme.textTheme.display1,
@@ -116,16 +114,16 @@
blockquotePadding: 8.0,
blockquoteDecoration: new BoxDecoration(
color: Colors.blue.shade100,
- borderRadius: new BorderRadius.circular(2.0)
+ borderRadius: new BorderRadius.circular(2.0),
),
codeblockPadding: 8.0,
codeblockDecoration: new BoxDecoration(
color: Colors.grey.shade100,
- borderRadius: new BorderRadius.circular(2.0)
+ borderRadius: new BorderRadius.circular(2.0),
),
horizontalRuleDecoration: new BoxDecoration(
border: new Border(
- top: new BorderSide(width: 5.0, color: Colors.grey.shade300)
+ top: new BorderSide(width: 5.0, color: Colors.grey.shade300),
),
),
);
@@ -176,8 +174,9 @@
blockquoteDecoration: blockquoteDecoration ?? this.blockquoteDecoration,
codeblockPadding: codeblockPadding ?? this.codeblockPadding,
codeblockDecoration: codeblockDecoration ?? this.codeblockDecoration,
- horizontalRuleDecoration: horizontalRuleDecoration ?? this.horizontalRuleDecoration,
- textScaleFactor : textScaleFactor ?? this.textScaleFactor,
+ horizontalRuleDecoration:
+ horizontalRuleDecoration ?? this.horizontalRuleDecoration,
+ textScaleFactor: textScaleFactor ?? this.textScaleFactor,
);
}
@@ -250,32 +249,30 @@
@override
bool operator ==(dynamic other) {
- if (identical(this, other))
- return true;
- if (other.runtimeType != MarkdownStyleSheet)
- return false;
+ if (identical(this, other)) return true;
+ if (other.runtimeType != MarkdownStyleSheet) return false;
final MarkdownStyleSheet typedOther = other;
- return typedOther.a == a
- && typedOther.p == p
- && typedOther.code == code
- && typedOther.h1 == h1
- && typedOther.h2 == h2
- && typedOther.h3 == h3
- && typedOther.h4 == h4
- && typedOther.h5 == h5
- && typedOther.h6 == h6
- && typedOther.em == em
- && typedOther.strong == strong
- && typedOther.blockquote == blockquote
- && typedOther.img == img
- && typedOther.blockSpacing == blockSpacing
- && typedOther.listIndent == listIndent
- && typedOther.blockquotePadding == blockquotePadding
- && typedOther.blockquoteDecoration == blockquoteDecoration
- && typedOther.codeblockPadding == codeblockPadding
- && typedOther.codeblockDecoration == codeblockDecoration
- && typedOther.horizontalRuleDecoration == horizontalRuleDecoration
- && typedOther.textScaleFactor == textScaleFactor;
+ return typedOther.a == a &&
+ typedOther.p == p &&
+ typedOther.code == code &&
+ typedOther.h1 == h1 &&
+ typedOther.h2 == h2 &&
+ typedOther.h3 == h3 &&
+ typedOther.h4 == h4 &&
+ typedOther.h5 == h5 &&
+ typedOther.h6 == h6 &&
+ typedOther.em == em &&
+ typedOther.strong == strong &&
+ typedOther.blockquote == blockquote &&
+ typedOther.img == img &&
+ typedOther.blockSpacing == blockSpacing &&
+ typedOther.listIndent == listIndent &&
+ typedOther.blockquotePadding == blockquotePadding &&
+ typedOther.blockquoteDecoration == blockquoteDecoration &&
+ typedOther.codeblockPadding == codeblockPadding &&
+ typedOther.codeblockDecoration == codeblockDecoration &&
+ typedOther.horizontalRuleDecoration == horizontalRuleDecoration &&
+ typedOther.textScaleFactor == textScaleFactor;
}
@override
diff --git a/packages/flutter_markdown/lib/src/widget.dart b/packages/flutter_markdown/lib/src/widget.dart
index 39a15c6..ccd8232 100644
--- a/packages/flutter_markdown/lib/src/widget.dart
+++ b/packages/flutter_markdown/lib/src/widget.dart
@@ -20,7 +20,8 @@
/// Creates a format [TextSpan] given a string.
///
/// Used by [MarkdownWidget] to highlight the contents of `pre` elements.
-abstract class SyntaxHighlighter { // ignore: one_member_abstracts
+abstract class SyntaxHighlighter {
+ // ignore: one_member_abstracts
/// Returns the formated [TextSpan] for the given string.
TextSpan format(String source);
}
@@ -46,8 +47,8 @@
this.syntaxHighlighter,
this.onTapLink,
this.imageDirectory,
- }) : assert(data != null),
- super(key: key);
+ }) : assert(data != null),
+ super(key: key);
/// The Markdown to display.
final String data;
@@ -77,7 +78,8 @@
_MarkdownWidgetState createState() => new _MarkdownWidgetState();
}
-class _MarkdownWidgetState extends State<MarkdownWidget> implements MarkdownBuilderDelegate {
+class _MarkdownWidgetState extends State<MarkdownWidget>
+ implements MarkdownBuilderDelegate {
List<Widget> _children;
final List<GestureRecognizer> _recognizers = <GestureRecognizer>[];
@@ -90,9 +92,8 @@
@override
void didUpdateWidget(MarkdownWidget oldWidget) {
super.didUpdateWidget(oldWidget);
- if (widget.data != oldWidget.data
- || widget.styleSheet != oldWidget.styleSheet)
- _parseMarkdown();
+ if (widget.data != oldWidget.data ||
+ widget.styleSheet != oldWidget.styleSheet) _parseMarkdown();
}
@override
@@ -102,7 +103,8 @@
}
void _parseMarkdown() {
- final MarkdownStyleSheet styleSheet = widget.styleSheet ?? new MarkdownStyleSheet.fromTheme(Theme.of(context));
+ final MarkdownStyleSheet styleSheet = widget.styleSheet ??
+ new MarkdownStyleSheet.fromTheme(Theme.of(context));
_disposeRecognizers();
@@ -118,21 +120,19 @@
}
void _disposeRecognizers() {
- if (_recognizers.isEmpty)
- return;
- final List<GestureRecognizer> localRecognizers = new List<GestureRecognizer>.from(_recognizers);
+ if (_recognizers.isEmpty) return;
+ final List<GestureRecognizer> localRecognizers =
+ new List<GestureRecognizer>.from(_recognizers);
_recognizers.clear();
- for (GestureRecognizer recognizer in localRecognizers)
- recognizer.dispose();
+ for (GestureRecognizer recognizer in localRecognizers) recognizer.dispose();
}
@override
GestureRecognizer createLink(String href) {
final TapGestureRecognizer recognizer = new TapGestureRecognizer()
..onTap = () {
- if (widget.onTapLink != null)
- widget.onTapLink(href);
- };
+ if (widget.onTapLink != null) widget.onTapLink(href);
+ };
_recognizers.add(recognizer);
return recognizer;
}
@@ -167,18 +167,17 @@
MarkdownTapLinkCallback onTapLink,
Directory imageDirectory,
}) : super(
- key: key,
- data: data,
- styleSheet: styleSheet,
- syntaxHighlighter: syntaxHighlighter,
- onTapLink: onTapLink,
- imageDirectory: imageDirectory,
- );
+ key: key,
+ data: data,
+ styleSheet: styleSheet,
+ syntaxHighlighter: syntaxHighlighter,
+ onTapLink: onTapLink,
+ imageDirectory: imageDirectory,
+ );
@override
Widget build(BuildContext context, List<Widget> children) {
- if (children.length == 1)
- return children.single;
+ if (children.length == 1) return children.single;
return new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: children,
@@ -206,13 +205,13 @@
Directory imageDirectory,
this.padding: const EdgeInsets.all(16.0),
}) : super(
- key: key,
- data: data,
- styleSheet: styleSheet,
- syntaxHighlighter: syntaxHighlighter,
- onTapLink: onTapLink,
- imageDirectory: imageDirectory,
- );
+ key: key,
+ data: data,
+ styleSheet: styleSheet,
+ syntaxHighlighter: syntaxHighlighter,
+ onTapLink: onTapLink,
+ imageDirectory: imageDirectory,
+ );
/// The amount of space by which to inset the children.
final EdgeInsets padding;
diff --git a/packages/flutter_markdown/pubspec.yaml b/packages/flutter_markdown/pubspec.yaml
index d4e6565..8509a73 100644
--- a/packages/flutter_markdown/pubspec.yaml
+++ b/packages/flutter_markdown/pubspec.yaml
@@ -19,3 +19,7 @@
environment:
sdk: '>=2.0.0-dev.58.0 <3.0.0'
+
+flutter:
+ assets:
+ - assets/logo.png
diff --git a/packages/flutter_markdown/test/flutter_markdown_test.dart b/packages/flutter_markdown/test/flutter_markdown_test.dart
index 3949800..1d51d61 100644
--- a/packages/flutter_markdown/test/flutter_markdown_test.dart
+++ b/packages/flutter_markdown/test/flutter_markdown_test.dart
@@ -128,10 +128,12 @@
final TextSpan span = textWidget.text;
final List<Type> gestureRecognizerTypes = <Type>[];
- span.visitTextSpan((TextSpan textSpan) {
- TapGestureRecognizer recognizer = textSpan.recognizer;
- gestureRecognizerTypes.add(recognizer.runtimeType);
- recognizer.onTap();
+ span.visitChildren((InlineSpan inlineSpan) {
+ if (inlineSpan is TextSpan) {
+ TapGestureRecognizer recognizer = inlineSpan.recognizer;
+ gestureRecognizerTypes.add(recognizer.runtimeType);
+ recognizer.onTap();
+ }
return true;
});
@@ -155,10 +157,12 @@
final TextSpan span = textWidget.text;
final List<Type> gestureRecognizerTypes = <Type>[];
- span.visitTextSpan((TextSpan textSpan) {
- TapGestureRecognizer recognizer = textSpan.recognizer;
- gestureRecognizerTypes.add(recognizer.runtimeType);
- recognizer?.onTap();
+ span.visitChildren((InlineSpan inlineSpan) {
+ if (inlineSpan is TextSpan) {
+ TapGestureRecognizer recognizer = inlineSpan.recognizer;
+ gestureRecognizerTypes.add(recognizer.runtimeType);
+ recognizer?.onTap();
+ }
return true;
});