Skip to content
Open
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
52 changes: 40 additions & 12 deletions lib/src/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ typedef MarkdownOnSelectionChangedCallback = void Function(
/// Markdown link tag in the document.
///
/// Used by [MarkdownWidget.onTapLink].
typedef MarkdownTapLinkCallback = void Function(String text, String? href, String title);
typedef MarkdownTapLinkCallback = void Function(
String text, String? href, String title);

/// Signature for custom image widget.
///
/// Used by [MarkdownWidget.imageBuilder]
typedef MarkdownImageBuilder = Widget Function(Uri uri, String? title, String? alt);
typedef MarkdownImageBuilder = Widget Function(
Uri uri, String? title, String? alt);

/// Signature for custom checkbox widget.
///
Expand Down Expand Up @@ -135,7 +137,8 @@ abstract class MarkdownElementBuilder {
///
/// If you needn't build a widget, return null.
@Deprecated('Use visitElementAfterWithContext() instead.')
Widget? visitElementAfter(md.Element element, TextStyle? preferredStyle) => null;
Widget? visitElementAfter(md.Element element, TextStyle? preferredStyle) =>
null;
}

/// Enum to specify which theme being used when creating [MarkdownStyleSheet]
Expand Down Expand Up @@ -223,7 +226,8 @@ abstract class MarkdownWidget extends StatefulWidget {
this.builders = const <String, MarkdownElementBuilder>{},
this.paddingBuilders = const <String, MarkdownPaddingBuilder>{},
this.fitContent = false,
this.listItemCrossAxisAlignment = MarkdownListItemCrossAxisAlignment.baseline,
this.listItemCrossAxisAlignment =
MarkdownListItemCrossAxisAlignment.baseline,
this.softLineBreak = false,
});

Expand Down Expand Up @@ -334,7 +338,8 @@ abstract class MarkdownWidget extends StatefulWidget {
State<MarkdownWidget> createState() => _MarkdownWidgetState();
}

class _MarkdownWidgetState extends State<MarkdownWidget> implements MarkdownBuilderDelegate {
class _MarkdownWidgetState extends State<MarkdownWidget>
implements MarkdownBuilderDelegate {
List<Widget>? _children;
final List<GestureRecognizer> _recognizers = <GestureRecognizer>[];

Expand All @@ -347,7 +352,8 @@ class _MarkdownWidgetState extends State<MarkdownWidget> implements MarkdownBuil
@override
void didUpdateWidget(MarkdownWidget oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.data != oldWidget.data || widget.styleSheet != oldWidget.styleSheet) {
if (widget.data != oldWidget.data ||
widget.styleSheet != oldWidget.styleSheet) {
_parseMarkdown();
}
}
Expand All @@ -359,8 +365,10 @@ class _MarkdownWidgetState extends State<MarkdownWidget> implements MarkdownBuil
}

void _parseMarkdown() {
final MarkdownStyleSheet fallbackStyleSheet = kFallbackStyle(context, widget.styleSheetTheme);
final MarkdownStyleSheet styleSheet = fallbackStyleSheet.merge(widget.styleSheet);
final MarkdownStyleSheet fallbackStyleSheet =
kFallbackStyle(context, widget.styleSheetTheme);
final MarkdownStyleSheet styleSheet =
fallbackStyleSheet.merge(widget.styleSheet);

_disposeRecognizers();

Expand Down Expand Up @@ -401,7 +409,8 @@ class _MarkdownWidgetState extends State<MarkdownWidget> implements MarkdownBuil
if (_recognizers.isEmpty) {
return;
}
final List<GestureRecognizer> localRecognizers = List<GestureRecognizer>.from(_recognizers);
final List<GestureRecognizer> localRecognizers =
List<GestureRecognizer>.from(_recognizers);
_recognizers.clear();
for (final GestureRecognizer recognizer in localRecognizers) {
recognizer.dispose();
Expand Down Expand Up @@ -481,7 +490,8 @@ class MarkdownBody extends MarkdownWidget {
}
return Column(
mainAxisSize: shrinkWrap ? MainAxisSize.min : MainAxisSize.max,
crossAxisAlignment: fitContent ? CrossAxisAlignment.start : CrossAxisAlignment.stretch,
crossAxisAlignment:
fitContent ? CrossAxisAlignment.start : CrossAxisAlignment.stretch,
children: children,
);
}
Expand Down Expand Up @@ -522,6 +532,7 @@ class Markdown extends MarkdownWidget {
this.controller,
this.physics,
this.shrinkWrap = false,
this.noScroll = false,
super.softLineBreak,
});

Expand All @@ -544,8 +555,23 @@ class Markdown extends MarkdownWidget {
/// See also: [ScrollView.shrinkWrap]
final bool shrinkWrap;

/// Use Row instead of ListView
final bool noScroll;

@override
Widget build(BuildContext context, List<Widget>? children) {
if (noScroll) {
final List<Widget> childrenWithPadding = [];
for (final Widget child in children!) {
childrenWithPadding.add(Padding(
padding: padding,
child: child,
));
}
return Column(
children: childrenWithPadding,
);
}
return ListView(
padding: padding,
controller: controller,
Expand All @@ -559,10 +585,12 @@ class Markdown extends MarkdownWidget {
/// Parse [task list items](https://github.github.com/gfm/#task-list-items-extension-).
///
/// This class is no longer used as Markdown now supports checkbox syntax natively.
@Deprecated('Use [OrderedListWithCheckBoxSyntax] or [UnorderedListWithCheckBoxSyntax]')
@Deprecated(
'Use [OrderedListWithCheckBoxSyntax] or [UnorderedListWithCheckBoxSyntax]')
class TaskListSyntax extends md.InlineSyntax {
/// Creates a new instance.
@Deprecated('Use [OrderedListWithCheckBoxSyntax] or [UnorderedListWithCheckBoxSyntax]')
@Deprecated(
'Use [OrderedListWithCheckBoxSyntax] or [UnorderedListWithCheckBoxSyntax]')
TaskListSyntax() : super(_pattern);

static const String _pattern = r'^ *\[([ xX])\] +';
Expand Down