2024-07-09 14:39:44 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-07-30 06:49:26 +00:00
|
|
|
import 'package:flutter_markdown_selectionarea/flutter_markdown.dart';
|
2024-07-09 14:39:44 +00:00
|
|
|
import 'package:markdown/markdown.dart' as markdown;
|
|
|
|
import 'package:url_launcher/url_launcher_string.dart';
|
|
|
|
|
2024-07-11 16:44:57 +00:00
|
|
|
class MarkdownTextContent extends StatelessWidget {
|
2024-07-09 14:39:44 +00:00
|
|
|
final String content;
|
2024-07-13 10:54:08 +00:00
|
|
|
final bool isSelectable;
|
2024-07-09 14:39:44 +00:00
|
|
|
|
2024-07-13 10:54:08 +00:00
|
|
|
const MarkdownTextContent({
|
|
|
|
super.key,
|
|
|
|
required this.content,
|
|
|
|
this.isSelectable = false,
|
|
|
|
});
|
2024-07-09 14:39:44 +00:00
|
|
|
|
2024-07-30 06:49:26 +00:00
|
|
|
Widget _buildContent(BuildContext context) {
|
2024-07-09 14:39:44 +00:00
|
|
|
return Markdown(
|
|
|
|
shrinkWrap: true,
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
data: content,
|
|
|
|
padding: EdgeInsets.zero,
|
2024-07-11 16:44:57 +00:00
|
|
|
styleSheet: MarkdownStyleSheet.fromTheme(Theme.of(context)).copyWith(
|
|
|
|
horizontalRuleDecoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
top: BorderSide(
|
|
|
|
width: 1.0,
|
|
|
|
color: Theme.of(context).dividerColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-07-09 14:39:44 +00:00
|
|
|
extensionSet: markdown.ExtensionSet(
|
|
|
|
markdown.ExtensionSet.gitHubFlavored.blockSyntaxes,
|
|
|
|
<markdown.InlineSyntax>[
|
|
|
|
markdown.EmojiSyntax(),
|
|
|
|
markdown.AutolinkExtensionSyntax(),
|
|
|
|
...markdown.ExtensionSet.gitHubFlavored.inlineSyntaxes
|
|
|
|
],
|
|
|
|
),
|
|
|
|
onTapLink: (text, href, title) async {
|
|
|
|
if (href == null) return;
|
|
|
|
await launchUrlString(
|
|
|
|
href,
|
|
|
|
mode: LaunchMode.externalApplication,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2024-07-30 06:49:26 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (isSelectable) {
|
|
|
|
return SelectionArea(child: _buildContent(context));
|
|
|
|
}
|
|
|
|
return _buildContent(context);
|
|
|
|
}
|
2024-07-09 14:39:44 +00:00
|
|
|
}
|