✨ Render article in feed
This commit is contained in:
		| @@ -71,6 +71,7 @@ class _ExploreScreenState extends State<ExploreScreen> { | ||||
|           builderDelegate: PagedChildBuilderDelegate<Feed>( | ||||
|             itemBuilder: (context, item, index) => FeedItem( | ||||
|               item: item, | ||||
|               brief: true, | ||||
|             ), | ||||
|           ), | ||||
|         ), | ||||
|   | ||||
| @@ -4,12 +4,15 @@ 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'; | ||||
| import 'package:solaragent/widgets/posts/content/article.dart'; | ||||
| import 'package:solaragent/widgets/posts/content/moment.dart'; | ||||
| import 'package:solaragent/widgets/posts/reactions.dart'; | ||||
|  | ||||
| class FeedItem extends StatefulWidget { | ||||
|   final Feed item; | ||||
|   final bool? brief; | ||||
|  | ||||
|   const FeedItem({super.key, required this.item}); | ||||
|   const FeedItem({super.key, required this.item, this.brief}); | ||||
|  | ||||
|   @override | ||||
|   State<FeedItem> createState() => _FeedItemState(); | ||||
| @@ -47,7 +50,9 @@ class _FeedItemState extends State<FeedItem> { | ||||
|   } | ||||
|  | ||||
|   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) => | ||||
|       desc.isEmpty ? "No description yet." : desc; | ||||
| @@ -55,6 +60,15 @@ class _FeedItemState extends State<FeedItem> { | ||||
|   String getFileUrl(String 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 | ||||
|   void initState() { | ||||
|     reactionCount = widget.item.reactionCount; | ||||
| @@ -66,7 +80,6 @@ class _FeedItemState extends State<FeedItem> { | ||||
|   Widget build(BuildContext context) { | ||||
|     return Column( | ||||
|       children: [ | ||||
|         // Author info | ||||
|         Container( | ||||
|           color: Colors.grey[50], | ||||
|           child: ListTile( | ||||
| @@ -82,13 +95,7 @@ class _FeedItemState extends State<FeedItem> { | ||||
|             ), | ||||
|           ), | ||||
|         ), | ||||
|         // Content | ||||
|         Markdown( | ||||
|           data: widget.item.content, | ||||
|           shrinkWrap: true, | ||||
|           physics: const NeverScrollableScrollPhysics(), | ||||
|         ), | ||||
|         // Attachments view | ||||
|         buildContent(), | ||||
|         hasAttachments() | ||||
|             ? Container( | ||||
|                 decoration: const BoxDecoration( | ||||
| @@ -97,7 +104,7 @@ class _FeedItemState extends State<FeedItem> { | ||||
|                 ), | ||||
|                 child: FlutterCarousel( | ||||
|                   options: CarouselOptions( | ||||
|                     height: 240.0, | ||||
|                     height: 360.0, | ||||
|                     viewportFraction: 1.0, | ||||
|                     showIndicator: true, | ||||
|                     slideIndicator: const CircularSlideIndicator(), | ||||
| @@ -128,12 +135,12 @@ class _FeedItemState extends State<FeedItem> { | ||||
|                 ), | ||||
|               ) | ||||
|             : Container(), | ||||
|         // Actions | ||||
|         Container( | ||||
|           padding: const EdgeInsets.symmetric(horizontal: 8), | ||||
|           decoration: const BoxDecoration( | ||||
|             border: | ||||
|                 Border(top: BorderSide(width: 0.3, color: Color(0xffdedede))), | ||||
|             border: Border( | ||||
|               top: BorderSide(width: 0.3, color: Color(0xffdedede)), | ||||
|             ), | ||||
|           ), | ||||
|           child: Row( | ||||
|             children: [ | ||||
|   | ||||
| @@ -113,6 +113,7 @@ class _CommentListState extends State<CommentList> { | ||||
|             builderDelegate: PagedChildBuilderDelegate<Feed>( | ||||
|               itemBuilder: (context, item, index) => FeedItem( | ||||
|                 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