68 lines
2.2 KiB
Dart
68 lines
2.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
|
import 'package:html2md/html2md.dart' as html2md;
|
|
import 'package:loris/dialogues/profile_view.dart';
|
|
import 'package:url_launcher/url_launcher.dart';
|
|
import '../business_logic/account/account.dart' as account;
|
|
|
|
class PostTextRenderer extends StatelessWidget {
|
|
const PostTextRenderer({
|
|
required this.identityName,
|
|
required this.input,
|
|
Key? key,
|
|
}) : super(key: key);
|
|
final String input;
|
|
final String identityName;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final MarkdownStyleSheet mdStyle = MarkdownStyleSheet(
|
|
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,
|
|
),
|
|
a: TextStyle(color: Theme.of(context).colorScheme.secondary),
|
|
blockquote: TextStyle(color: Theme.of(context).colorScheme.onBackground),
|
|
blockquoteDecoration: 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,
|
|
),
|
|
),
|
|
);
|
|
|
|
String s = html2md.convert(input);
|
|
return MarkdownBody(
|
|
onTapLink: ((text, href, title) async {
|
|
if (href != null) {
|
|
if (text.startsWith("@")) {
|
|
final result = await account.searchModel(identityName, href);
|
|
if (result.keys.first == 200) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => ProfileView(model: result.values.first!),
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
launchUrl(Uri.parse(href));
|
|
}
|
|
}),
|
|
styleSheet: mdStyle,
|
|
data: s,
|
|
selectable: true,
|
|
);
|
|
}
|
|
}
|