Solian/lib/widgets/posts/content/article.dart

69 lines
2.2 KiB
Dart
Raw Normal View History

2024-04-13 11:47:31 +00:00
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:solian/models/post.dart';
import 'package:markdown/markdown.dart' as markdown;
2024-04-13 17:45:27 +00:00
import 'package:solian/utils/service_url.dart';
2024-04-13 11:47:31 +00:00
import 'package:url_launcher/url_launcher_string.dart';
class ArticleContent extends StatelessWidget {
final Post item;
final bool brief;
const ArticleContent({super.key, required this.item, required this.brief});
@override
Widget build(BuildContext context) {
2024-04-13 17:45:27 +00:00
final headingPart = Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
item.title,
style: Theme.of(context).textTheme.titleMedium,
),
Text(
item.description,
style: Theme.of(context).textTheme.bodyMedium,
2024-04-13 11:47:31 +00:00
)
2024-04-13 17:45:27 +00:00
],
);
return brief
? headingPart
2024-04-13 11:47:31 +00:00
: Column(
children: [
2024-04-13 17:45:27 +00:00
Padding(
padding: const EdgeInsets.only(bottom: 12),
child: headingPart,
2024-04-13 11:47:31 +00:00
),
Markdown(
2024-04-13 17:45:27 +00:00
padding: const EdgeInsets.all(0),
2024-04-13 11:47:31 +00:00
selectable: !brief,
data: item.content,
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
extensionSet: markdown.ExtensionSet(
markdown.ExtensionSet.gitHubFlavored.blockSyntaxes,
markdown.ExtensionSet.gitHubFlavored.inlineSyntaxes,
),
onTapLink: (text, href, title) async {
if (href == null) return;
await launchUrlString(
href,
mode: LaunchMode.externalApplication,
);
},
2024-04-13 17:45:27 +00:00
imageBuilder: (url, _, __) {
if (url.toString().startsWith("/api/attachments")) {
return Image.network(
getRequestUri('interactive', url.toString())
.toString());
} else {
return Image.network(url.toString());
}
},
2024-04-13 11:47:31 +00:00
),
],
);
}
}