2022-08-06 16:46:31 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-28 18:55:23 +00:00
|
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
|
|
|
import 'package:html2md/html2md.dart' as html2md;
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2022-08-06 16:46:31 +00:00
|
|
|
|
|
|
|
class PostTextRenderer extends StatelessWidget {
|
|
|
|
const PostTextRenderer({
|
2022-08-28 18:55:23 +00:00
|
|
|
required this.input,
|
2022-08-06 16:46:31 +00:00
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
2022-08-28 18:55:23 +00:00
|
|
|
final String input;
|
2022-08-06 16:46:31 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-29 21:16:13 +00:00
|
|
|
final MarkdownStyleSheet mdStyle = MarkdownStyleSheet(
|
2022-09-04 12:00:24 +00:00
|
|
|
codeblockDecoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).colorScheme.background,
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
|
border: Border.all(
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
style: BorderStyle.solid,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
code: TextStyle(
|
|
|
|
decorationColor: Theme.of(context).backgroundColor,
|
|
|
|
color: Theme.of(context).colorScheme.onBackground,
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
),
|
2022-08-29 21:16:13 +00:00
|
|
|
a: TextStyle(color: Theme.of(context).colorScheme.secondary),
|
|
|
|
blockquoteDecoration: BoxDecoration(
|
2022-09-04 12:00:24 +00:00
|
|
|
color: Theme.of(context).colorScheme.background,
|
2022-08-29 21:16:13 +00:00
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
|
|
border: Border.all(
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
style: BorderStyle.solid,
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
2022-08-28 18:55:23 +00:00
|
|
|
String s = html2md.convert(input);
|
|
|
|
return MarkdownBody(
|
|
|
|
onTapLink: ((text, href, title) {
|
|
|
|
if (href != null) {
|
|
|
|
launchUrl(Uri.parse(href));
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
styleSheet: mdStyle,
|
|
|
|
data: s,
|
|
|
|
selectable: true,
|
2022-08-12 19:30:58 +00:00
|
|
|
);
|
2022-08-06 16:46:31 +00:00
|
|
|
}
|
|
|
|
}
|