✨ Render article in feed
This commit is contained in:
parent
52304a7633
commit
217c20164f
@ -71,6 +71,7 @@ class _ExploreScreenState extends State<ExploreScreen> {
|
|||||||
builderDelegate: PagedChildBuilderDelegate<Feed>(
|
builderDelegate: PagedChildBuilderDelegate<Feed>(
|
||||||
itemBuilder: (context, item, index) => FeedItem(
|
itemBuilder: (context, item, index) => FeedItem(
|
||||||
item: item,
|
item: item,
|
||||||
|
brief: true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -4,12 +4,15 @@ import 'package:flutter_markdown/flutter_markdown.dart';
|
|||||||
import 'package:solaragent/models/feed.dart';
|
import 'package:solaragent/models/feed.dart';
|
||||||
import 'package:solaragent/widgets/image.dart';
|
import 'package:solaragent/widgets/image.dart';
|
||||||
import 'package:solaragent/widgets/posts/comments.dart';
|
import 'package:solaragent/widgets/posts/comments.dart';
|
||||||
|
import 'package:solaragent/widgets/posts/content/article.dart';
|
||||||
|
import 'package:solaragent/widgets/posts/content/moment.dart';
|
||||||
import 'package:solaragent/widgets/posts/reactions.dart';
|
import 'package:solaragent/widgets/posts/reactions.dart';
|
||||||
|
|
||||||
class FeedItem extends StatefulWidget {
|
class FeedItem extends StatefulWidget {
|
||||||
final Feed item;
|
final Feed item;
|
||||||
|
final bool? brief;
|
||||||
|
|
||||||
const FeedItem({super.key, required this.item});
|
const FeedItem({super.key, required this.item, this.brief});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<FeedItem> createState() => _FeedItemState();
|
State<FeedItem> createState() => _FeedItemState();
|
||||||
@ -47,7 +50,9 @@ class _FeedItemState extends State<FeedItem> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool hasAttachments() =>
|
bool hasAttachments() =>
|
||||||
widget.item.attachments != null && widget.item.attachments!.isNotEmpty;
|
widget.item.modelType == "moment" &&
|
||||||
|
widget.item.attachments != null &&
|
||||||
|
widget.item.attachments!.isNotEmpty;
|
||||||
|
|
||||||
String getDescription(String desc) =>
|
String getDescription(String desc) =>
|
||||||
desc.isEmpty ? "No description yet." : desc;
|
desc.isEmpty ? "No description yet." : desc;
|
||||||
@ -55,6 +60,15 @@ class _FeedItemState extends State<FeedItem> {
|
|||||||
String getFileUrl(String fileId) =>
|
String getFileUrl(String fileId) =>
|
||||||
'https://co.solsynth.dev/api/attachments/o/$fileId';
|
'https://co.solsynth.dev/api/attachments/o/$fileId';
|
||||||
|
|
||||||
|
Widget buildContent() {
|
||||||
|
switch (widget.item.modelType) {
|
||||||
|
case "article":
|
||||||
|
return ArticleContent(item: widget.item, brief: widget.brief ?? false);
|
||||||
|
default:
|
||||||
|
return MomentContent(item: widget.item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
reactionCount = widget.item.reactionCount;
|
reactionCount = widget.item.reactionCount;
|
||||||
@ -66,7 +80,6 @@ class _FeedItemState extends State<FeedItem> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
// Author info
|
|
||||||
Container(
|
Container(
|
||||||
color: Colors.grey[50],
|
color: Colors.grey[50],
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
@ -82,13 +95,7 @@ class _FeedItemState extends State<FeedItem> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// Content
|
buildContent(),
|
||||||
Markdown(
|
|
||||||
data: widget.item.content,
|
|
||||||
shrinkWrap: true,
|
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
|
||||||
),
|
|
||||||
// Attachments view
|
|
||||||
hasAttachments()
|
hasAttachments()
|
||||||
? Container(
|
? Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
@ -97,7 +104,7 @@ class _FeedItemState extends State<FeedItem> {
|
|||||||
),
|
),
|
||||||
child: FlutterCarousel(
|
child: FlutterCarousel(
|
||||||
options: CarouselOptions(
|
options: CarouselOptions(
|
||||||
height: 240.0,
|
height: 360.0,
|
||||||
viewportFraction: 1.0,
|
viewportFraction: 1.0,
|
||||||
showIndicator: true,
|
showIndicator: true,
|
||||||
slideIndicator: const CircularSlideIndicator(),
|
slideIndicator: const CircularSlideIndicator(),
|
||||||
@ -128,12 +135,12 @@ class _FeedItemState extends State<FeedItem> {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
: Container(),
|
: Container(),
|
||||||
// Actions
|
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
border:
|
border: Border(
|
||||||
Border(top: BorderSide(width: 0.3, color: Color(0xffdedede))),
|
top: BorderSide(width: 0.3, color: Color(0xffdedede)),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
@ -113,6 +113,7 @@ class _CommentListState extends State<CommentList> {
|
|||||||
builderDelegate: PagedChildBuilderDelegate<Feed>(
|
builderDelegate: PagedChildBuilderDelegate<Feed>(
|
||||||
itemBuilder: (context, item, index) => FeedItem(
|
itemBuilder: (context, item, index) => FeedItem(
|
||||||
item: item,
|
item: item,
|
||||||
|
brief: true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
24
lib/widgets/posts/content/article.dart
Normal file
24
lib/widgets/posts/content/article.dart
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||||
|
import 'package:solaragent/models/feed.dart';
|
||||||
|
|
||||||
|
class ArticleContent extends StatelessWidget {
|
||||||
|
final Feed item;
|
||||||
|
final bool brief;
|
||||||
|
|
||||||
|
const ArticleContent({super.key, required this.item, required this.brief});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return brief
|
||||||
|
? ListTile(
|
||||||
|
title: Text(item.title),
|
||||||
|
subtitle: Text(item.description),
|
||||||
|
)
|
||||||
|
: Markdown(
|
||||||
|
data: item.content,
|
||||||
|
shrinkWrap: true,
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
18
lib/widgets/posts/content/moment.dart
Normal file
18
lib/widgets/posts/content/moment.dart
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||||
|
import 'package:solaragent/models/feed.dart';
|
||||||
|
|
||||||
|
class MomentContent extends StatelessWidget {
|
||||||
|
final Feed item;
|
||||||
|
|
||||||
|
const MomentContent({super.key, required this.item});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Markdown(
|
||||||
|
data: item.content,
|
||||||
|
shrinkWrap: true,
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user