import 'package:flutter/material.dart'; import 'package:flutter_carousel_widget/flutter_carousel_widget.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:solaragent/models/feed.dart'; import 'package:solaragent/widgets/image.dart'; import 'package:solaragent/widgets/posts/comments.dart'; class FeedItem extends StatelessWidget { final Feed item; const FeedItem({super.key, required this.item}); void viewComments(BuildContext context) { showModalBottomSheet( context: context, isScrollControlled: true, builder: (context) => CommentListWidget(parent: item), ); } bool hasAttachments() => item.attachments != null && item.attachments!.isNotEmpty; String getDescription(String desc) => desc.isEmpty ? "No description yet." : desc; String getFileUrl(String fileId) => 'https://co.solsynth.dev/api/attachments/o/$fileId'; @override Widget build(BuildContext context) { return Column( children: [ // Author info Container( color: Colors.grey[50], child: ListTile( title: Text(item.author.name), leading: CircleAvatar( backgroundImage: NetworkImage(item.author.avatar), ), subtitle: Text( getDescription(item.author.description), overflow: TextOverflow.ellipsis, maxLines: 1, softWrap: false, ), ), ), // Content Markdown( data: item.content, shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), ), // Attachments view hasAttachments() ? Container( decoration: const BoxDecoration( border: Border( top: BorderSide(width: 0.3, color: Color(0xffdedede))), ), child: FlutterCarousel( options: CarouselOptions( height: 240.0, viewportFraction: 1.0, showIndicator: true, slideIndicator: const CircularSlideIndicator(), ), items: item.attachments?.map((x) { return Builder( builder: (BuildContext context) { return SizedBox( width: MediaQuery.of(context).size.width, child: InkWell( child: Image.network( getFileUrl(x.fileId), fit: BoxFit.cover, ), onTap: () { Navigator.push(context, MaterialPageRoute(builder: (_) { return ImageLightbox( url: getFileUrl(x.fileId), ); })); }, ), ); }, ); }).toList(), ), ) : Container(), // Actions Container( padding: const EdgeInsets.symmetric(horizontal: 8), decoration: const BoxDecoration( border: Border(top: BorderSide(width: 0.3, color: Color(0xffdedede))), ), child: Row( children: [ TextButton.icon( icon: const Icon(Icons.comment), label: Text(item.commentCount.toString()), onPressed: () => viewComments(context), ) ], ), ), ], ); } }