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

74 lines
2.4 KiB
Dart
Raw Normal View History

2024-05-05 15:01:08 +00:00
import 'package:cached_network_image/cached_network_image.dart';
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-05-05 15:01:08 +00:00
import 'package:solian/utils/platform.dart';
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, _, __) {
2024-04-15 15:08:32 +00:00
Uri uri;
2024-05-01 16:49:38 +00:00
if (url.toString().startsWith('/api/attachments')) {
2024-04-15 15:08:32 +00:00
uri = getRequestUri('interactive', url.toString());
2024-04-13 17:45:27 +00:00
} else {
2024-04-15 15:08:32 +00:00
uri = url;
2024-04-13 17:45:27 +00:00
}
2024-04-15 15:08:32 +00:00
2024-05-05 15:01:08 +00:00
return PlatformInfo.canCacheImage
? CachedNetworkImage(imageUrl: uri.toString())
: Image.network(uri.toString());
2024-04-13 17:45:27 +00:00
},
2024-04-13 11:47:31 +00:00
),
],
);
}
}