123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- import 'package:flutter/material.dart';
- import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
- import 'package:url_launcher/url_launcher.dart';
- import 'package:veloe_kemono_party_flutter/models/attachment.dart';
- import 'smart_image_container.dart';
- import '../../models/post.dart';
- class PostContainer extends StatelessWidget {
- final Post post;
- const PostContainer({super.key, required this.post});
- @override
- Widget build(BuildContext context) {
- return Card(
- margin: const EdgeInsets.all(8),
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- // Post Header
- _PostHeader(post: post),
-
- // Auto-sizing Content
- _PostContentSection(post: post),
-
- // Interactive Footer
- _PostActionsFooter(post: post),
- ],
- ),
- ),
- );
- }
- }
- // New header component
- class _PostHeader extends StatelessWidget {
- final Post post;
- const _PostHeader({required this.post});
- @override
- Widget build(BuildContext context) {
- return Padding(
- padding: const EdgeInsets.only(bottom: 12),
- child: Row(
- children: [
- // Author avatar
- /*CircleAvatar(
- backgroundImage: NetworkImage(post.author),
- radius: 20,
- ),*/
- const SizedBox(width: 12),
- // Author info
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- post.title,
- style: Theme.of(context).textTheme.titleMedium?.copyWith(
- fontWeight: FontWeight.w600,
- ),
- ),
- Text(
- post.published,
- style: Theme.of(context).textTheme.bodySmall,
- ),
- ],
- ),
- ),
- // Time and menu
- Text(
- post.published,
- style: Theme.of(context).textTheme.bodySmall,
- ),
- /*IconButton(
- icon: const Icon(Icons.more_vert),
- onPressed: () => _showPostMenu(context),
- ),*/
- ],
- ),
- );
- }
- }
- // New footer component
- class _PostActionsFooter extends StatelessWidget {
- final Post post;
- const _PostActionsFooter({required this.post});
- @override
- Widget build(BuildContext context) {
- return Padding(
- padding: const EdgeInsets.only(top: 12),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- // Interactive buttons
- Row(
- children: [/*
- IconButton(
- icon: Icon(
- post.isLiked ? Icons.favorite : Icons.favorite_border,
- color: post.isLiked ? Colors.red : null,
- ),
- onPressed: () => _toggleLike(),
- ),
- Text(_formatCount(post.likeCount)),
- const SizedBox(width: 16),
- IconButton(
- icon: const Icon(Icons.comment_outlined),
- onPressed: () => _showComments(),
- ),
- Text(_formatCount(post.commentCount)),
- */],
- ),
- // Share button
- IconButton(
- icon: const Icon(Icons.share_outlined),
- onPressed: () => _sharePost(post),
- ),
- ],
- ),
- );
- }
- }
- void _sharePost(Post post) {
- //create link to share
- }
- // Modified content section with clickable links
- class _PostContentSection extends StatelessWidget {
- final Post post;
- const _PostContentSection({required this.post});
- @override
- Widget build(BuildContext context) {
- return Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- // Text Content
- HtmlWidget(
- post.content,
- textStyle: Theme.of(context).textTheme.bodyMedium,
- onTapUrl: (url) => _handleUrlLaunch(context, url),
- ),
- // Attachments Grid
- if (post.attachments.isNotEmpty)
- LayoutBuilder(
- builder: (context, constraints) {
- return Column(
- children: [
- const SizedBox(height: 12),
- GridView.builder(
- shrinkWrap: true,
- physics: const NeverScrollableScrollPhysics(),
- gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
- crossAxisCount: _calculateColumnCount(constraints.maxWidth),
- ),
- itemCount: post.attachments.length,
- itemBuilder: (context, index) => Padding(
- padding: const EdgeInsets.all(4),
- child: SmartImageContainer(
- imageUrl: post.attachments[index].link,
- //onTap: () => _handleAttachmentTap(index),
- ),
- ),
- ),
- // Attachment links list
- ...post.attachments.map(
- (attachment) => _buildAttachmentLink(context,attachment),
- ),
- ],
- );
- },
- ),
- ],
- );
- }
- Widget _buildAttachmentLink(BuildContext context,Attachment attachment) {
- return Padding(
- padding: const EdgeInsets.only(top: 8),
- child: InkWell(
- onTap: () => _handleUrlLaunch(context, attachment.link),
- child: Row(
- children: [
- const Icon(Icons.link, size: 16),
- const SizedBox(width: 8),
- Expanded(
- child: Text(
- attachment.name ?? _parseFileName(attachment.link),
- style: const TextStyle(
- color: Colors.blue,
- decoration: TextDecoration.underline,
- ),
- overflow: TextOverflow.ellipsis,
- ),
- ),
- ],
- ),
- ),
- );
- }
- int _calculateColumnCount(double availableWidth) {
- return (availableWidth / 400).floor().clamp(1, 3);
- }
- String _parseFileName(String url) {
- try {
- return Uri.parse(url).pathSegments.last;
- } catch (e) {
- return 'Download';
- }
- }
- }
- // URL handling method (add to parent class)
- Future<bool> _handleUrlLaunch(BuildContext context, String url) async {
- try {
- if (await canLaunchUrl(Uri.parse(url))) {
- await launchUrl(
- Uri.parse(url),
- mode: LaunchMode.externalApplication,
- );
- }
- } catch (e) {
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(content: Text('Could not open link: ${e.toString()}')),
- );
- }
- return true;
- }
|