38 lines
1.0 KiB
Dart
38 lines
1.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
|
import 'package:html2md/html2md.dart' as html2md;
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
|
|
class PostTextRenderer extends StatelessWidget {
|
|
const PostTextRenderer({
|
|
required this.input,
|
|
Key? key,
|
|
}) : super(key: key);
|
|
final String input;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final MarkdownStyleSheet mdStyle = MarkdownStyleSheet(
|
|
a: TextStyle(color: Theme.of(context).colorScheme.secondary),
|
|
blockquoteDecoration: BoxDecoration(
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
border: Border.all(
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
style: BorderStyle.solid,
|
|
)),
|
|
);
|
|
|
|
String s = html2md.convert(input);
|
|
return MarkdownBody(
|
|
onTapLink: ((text, href, title) {
|
|
if (href != null) {
|
|
launchUrl(Uri.parse(href));
|
|
}
|
|
}),
|
|
styleSheet: mdStyle,
|
|
data: s,
|
|
selectable: true,
|
|
);
|
|
}
|
|
}
|