2024-03-23 15:05:04 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-03-23 16:13:52 +00:00
|
|
|
import 'package:flutter_carousel_widget/flutter_carousel_widget.dart';
|
2024-03-23 15:05:04 +00:00
|
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
|
|
|
import 'package:solaragent/models/feed.dart';
|
2024-03-23 16:13:52 +00:00
|
|
|
import 'package:solaragent/widgets/image.dart';
|
2024-03-23 15:05:04 +00:00
|
|
|
|
|
|
|
class FeedItem extends StatelessWidget {
|
|
|
|
final Feed item;
|
|
|
|
|
|
|
|
const FeedItem({super.key, required this.item});
|
|
|
|
|
2024-03-23 16:13:52 +00:00
|
|
|
bool hasAttachments() =>
|
|
|
|
item.attachments != null && item.attachments!.isNotEmpty;
|
|
|
|
|
2024-03-23 15:05:04 +00:00
|
|
|
String getDescription(String desc) =>
|
|
|
|
desc.isEmpty ? "No description yet." : desc;
|
|
|
|
|
2024-03-23 16:13:52 +00:00
|
|
|
String getFileUrl(String fileId) =>
|
|
|
|
'https://co.solsynth.dev/api/attachments/o/$fileId';
|
|
|
|
|
2024-03-23 15:05:04 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-03-23 17:22:01 +00:00
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
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,
|
2024-03-23 15:05:04 +00:00
|
|
|
),
|
|
|
|
),
|
2024-03-23 17:22:01 +00:00
|
|
|
),
|
|
|
|
Markdown(
|
|
|
|
data: item.content,
|
|
|
|
shrinkWrap: true,
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
),
|
|
|
|
hasAttachments()
|
|
|
|
? Container(
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
top: BorderSide(width: 0.3, color: Color(0xffdedede))),
|
|
|
|
),
|
|
|
|
child: FlutterCarousel(
|
|
|
|
options: CarouselOptions(
|
|
|
|
height: 240.0,
|
2024-03-24 03:20:59 +00:00
|
|
|
viewportFraction: 1.0,
|
2024-03-23 17:22:01 +00:00
|
|
|
showIndicator: true,
|
|
|
|
slideIndicator: const CircularSlideIndicator(),
|
2024-03-23 16:13:52 +00:00
|
|
|
),
|
2024-03-23 17:22:01 +00:00
|
|
|
items: item.attachments?.map((x) {
|
|
|
|
return Builder(
|
|
|
|
builder: (BuildContext context) {
|
2024-03-24 03:20:59 +00:00
|
|
|
return SizedBox(
|
2024-03-23 17:22:01 +00:00
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
child: InkWell(
|
|
|
|
child: Image.network(
|
|
|
|
getFileUrl(x.fileId),
|
|
|
|
fit: BoxFit.cover,
|
2024-03-23 16:13:52 +00:00
|
|
|
),
|
2024-03-23 17:22:01 +00:00
|
|
|
onTap: () {
|
|
|
|
Navigator.push(context,
|
|
|
|
MaterialPageRoute(builder: (_) {
|
|
|
|
return ImageLightbox(
|
|
|
|
url: getFileUrl(x.fileId),
|
|
|
|
);
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Container(),
|
|
|
|
],
|
2024-03-23 15:05:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|