👔 Article wont show expand attachment list
This commit is contained in:
		| @@ -125,6 +125,21 @@ class PostEditorController extends GetxController { | ||||
|         onRemove: (String value) { | ||||
|           attachments.remove(value); | ||||
|         }, | ||||
|         onInsert: (String str) { | ||||
|           final text = contentController.text; | ||||
|           final selection = contentController.selection; | ||||
|           final newText = text.replaceRange( | ||||
|             selection.start, | ||||
|             selection.end, | ||||
|             str, | ||||
|           ); | ||||
|           contentController.value = TextEditingValue( | ||||
|             text: newText, | ||||
|             selection: TextSelection.collapsed( | ||||
|               offset: selection.baseOffset + str.length, | ||||
|             ), | ||||
|           ); | ||||
|         }, | ||||
|       ), | ||||
|     ); | ||||
|   } | ||||
|   | ||||
| @@ -33,12 +33,14 @@ class AttachmentEditorPopup extends StatefulWidget { | ||||
|   final List<String>? initialAttachments; | ||||
|   final void Function(String) onAdd; | ||||
|   final void Function(String) onRemove; | ||||
|   final void Function(String)? onInsert; | ||||
|  | ||||
|   const AttachmentEditorPopup({ | ||||
|     super.key, | ||||
|     required this.pool, | ||||
|     required this.onAdd, | ||||
|     required this.onRemove, | ||||
|     this.onInsert, | ||||
|     this.singleMode = false, | ||||
|     this.imageOnly = false, | ||||
|     this.autoUpload = false, | ||||
| @@ -557,6 +559,22 @@ class _AttachmentEditorPopupState extends State<AttachmentEditorPopup> { | ||||
|                           setState(() => _attachments.removeAt(idx)); | ||||
|                         }, | ||||
|                       ), | ||||
|                       if (widget.onInsert != null) | ||||
|                         PopupMenuItem( | ||||
|                           child: ListTile( | ||||
|                             title: Text('insert'.tr), | ||||
|                             leading: const Icon(Icons.insert_link), | ||||
|                             contentPadding: const EdgeInsets.symmetric( | ||||
|                               horizontal: 8, | ||||
|                             ), | ||||
|                           ), | ||||
|                           onTap: () { | ||||
|                             widget.onInsert!( | ||||
|                               '', | ||||
|                             ); | ||||
|                             Navigator.pop(context); | ||||
|                           }, | ||||
|                         ), | ||||
|                     ], | ||||
|                   ), | ||||
|                 ], | ||||
|   | ||||
| @@ -287,6 +287,16 @@ class _AttachmentFullScreenState extends State<AttachmentFullScreen> { | ||||
|                             '${widget.item.metadata?['width']}x${widget.item.metadata?['height']}', | ||||
|                             style: metaTextStyle, | ||||
|                           ), | ||||
|                           if (widget.item.metadata?['ratio'] != null) | ||||
|                             Text( | ||||
|                               (widget.item.metadata?['ratio'] as num) | ||||
|                                   .toStringAsFixed(2), | ||||
|                               style: metaTextStyle, | ||||
|                             ), | ||||
|                           Text( | ||||
|                             widget.item.mimetype, | ||||
|                             style: metaTextStyle, | ||||
|                           ), | ||||
|                         ], | ||||
|                       ), | ||||
|                     ), | ||||
|   | ||||
| @@ -1,4 +1,3 @@ | ||||
| import 'dart:developer'; | ||||
| import 'dart:ui'; | ||||
|  | ||||
| import 'package:flutter/material.dart'; | ||||
| @@ -7,7 +6,9 @@ import 'package:get/get.dart'; | ||||
| import 'package:google_fonts/google_fonts.dart'; | ||||
| import 'package:markdown/markdown.dart' as markdown; | ||||
| import 'package:path/path.dart'; | ||||
| import 'package:solian/models/attachment.dart'; | ||||
| import 'package:solian/providers/stickers.dart'; | ||||
| import 'package:solian/widgets/attachments/attachment_item.dart'; | ||||
| import 'package:solian/widgets/attachments/attachment_list.dart'; | ||||
| import 'package:solian/widgets/auto_cache_image.dart'; | ||||
| import 'package:syntax_highlight/syntax_highlight.dart'; | ||||
| @@ -18,6 +19,7 @@ import 'account/account_profile_popup.dart'; | ||||
| class MarkdownTextContent extends StatefulWidget { | ||||
|   final String content; | ||||
|   final String parentId; | ||||
|   final List<Attachment>? attachments; | ||||
|   final bool isSelectable; | ||||
|   final bool isLargeText; | ||||
|   final bool isAutoWarp; | ||||
| @@ -26,6 +28,7 @@ class MarkdownTextContent extends StatefulWidget { | ||||
|     super.key, | ||||
|     required this.content, | ||||
|     required this.parentId, | ||||
|     this.attachments, | ||||
|     this.isSelectable = false, | ||||
|     this.isLargeText = false, | ||||
|     this.isAutoWarp = false, | ||||
| @@ -189,18 +192,42 @@ class _MarkdownTextContentState extends State<MarkdownTextContent> { | ||||
|                 ), | ||||
|               ).paddingSymmetric(vertical: 4); | ||||
|             case 'attachments': | ||||
|               final match = widget.attachments | ||||
|                   ?.where((x) => x.rid == segments[1]) | ||||
|                   .firstOrNull; | ||||
|               const radius = BorderRadius.all(Radius.circular(8)); | ||||
|               return LimitedBox( | ||||
|                 maxHeight: MediaQuery.of(context).size.width, | ||||
|                 child: ClipRRect( | ||||
|                   borderRadius: radius, | ||||
|                   child: AttachmentSelfContainedEntry( | ||||
|                     isDense: true, | ||||
|                     parentId: widget.parentId, | ||||
|                     rid: segments[1], | ||||
|               if (match != null) { | ||||
|                 final isImage = | ||||
|                     match.mimetype.split('/').firstOrNull == 'image'; | ||||
|                 double ratio = match.metadata?['ratio']?.toDouble() ?? | ||||
|                     (isImage ? 1 : 16 / 9); | ||||
|                 return LimitedBox( | ||||
|                   maxWidth: 480, | ||||
|                   maxHeight: 640, | ||||
|                   child: AspectRatio( | ||||
|                     aspectRatio: ratio, | ||||
|                     child: ClipRRect( | ||||
|                       borderRadius: radius, | ||||
|                       child: AttachmentItem( | ||||
|                         parentId: widget.parentId, | ||||
|                         item: match, | ||||
|                       ), | ||||
|                     ), | ||||
|                   ), | ||||
|                 ), | ||||
|               ).paddingSymmetric(vertical: 4); | ||||
|                 ).paddingSymmetric(vertical: 4); | ||||
|               } else { | ||||
|                 return LimitedBox( | ||||
|                   maxHeight: MediaQuery.of(context).size.width, | ||||
|                   child: ClipRRect( | ||||
|                     borderRadius: radius, | ||||
|                     child: AttachmentSelfContainedEntry( | ||||
|                       isDense: true, | ||||
|                       parentId: widget.parentId, | ||||
|                       rid: segments[1], | ||||
|                     ), | ||||
|                   ), | ||||
|                 ).paddingSymmetric(vertical: 4); | ||||
|               } | ||||
|           } | ||||
|         } | ||||
|         return AutoCacheImage( | ||||
|   | ||||
| @@ -110,6 +110,7 @@ class _PostItemState extends State<PostItem> { | ||||
|             child: MarkdownTextContent( | ||||
|               parentId: 'p${item.id}', | ||||
|               content: item.body['content'], | ||||
|               attachments: item.preload?.attachments, | ||||
|               isAutoWarp: item.type == 'story', | ||||
|               isSelectable: widget.isContentSelectable, | ||||
|             ), | ||||
| @@ -131,20 +132,11 @@ class _PostItemState extends State<PostItem> { | ||||
|             right: 8, | ||||
|           ), | ||||
|           if (attachments.isNotEmpty) | ||||
|             Row( | ||||
|               children: [ | ||||
|                 Icon( | ||||
|                   Icons.file_copy, | ||||
|                   size: 15, | ||||
|                   color: _unFocusColor, | ||||
|                 ).paddingOnly(right: 5), | ||||
|                 Text( | ||||
|                   'attachmentHint'.trParams( | ||||
|                     {'count': attachments.length.toString()}, | ||||
|                   ), | ||||
|                   style: TextStyle(color: _unFocusColor), | ||||
|                 ) | ||||
|               ], | ||||
|             _PostAttachmentWidget( | ||||
|               item: item, | ||||
|               padding: widget.padding, | ||||
|               isCompact: true, | ||||
|               isNonScrollAttachment: widget.isNonScrollAttachment, | ||||
|             ).paddingOnly(left: 14, top: 4), | ||||
|         ], | ||||
|       ); | ||||
| @@ -173,6 +165,7 @@ class _PostItemState extends State<PostItem> { | ||||
|                 child: MarkdownTextContent( | ||||
|                   parentId: 'p${item.id}-embed', | ||||
|                   content: item.body['content'], | ||||
|                   attachments: item.preload?.attachments, | ||||
|                   isAutoWarp: item.type == 'story', | ||||
|                   isSelectable: widget.isContentSelectable, | ||||
|                 ), | ||||
| @@ -220,6 +213,7 @@ class _PostItemState extends State<PostItem> { | ||||
|           _PostAttachmentWidget( | ||||
|             item: item, | ||||
|             padding: widget.padding, | ||||
|             isCompact: item.type == 'article', | ||||
|             isNonScrollAttachment: widget.isNonScrollAttachment, | ||||
|           ), | ||||
|           if (widget.showFeaturedReply) | ||||
| @@ -388,11 +382,13 @@ class _PostAttachmentWidget extends StatelessWidget { | ||||
|   final Post item; | ||||
|   final EdgeInsets? padding; | ||||
|   final bool isNonScrollAttachment; | ||||
|   final bool isCompact; | ||||
|  | ||||
|   const _PostAttachmentWidget({ | ||||
|     required this.item, | ||||
|     required this.padding, | ||||
|     required this.isNonScrollAttachment, | ||||
|     this.isCompact = false, | ||||
|   }); | ||||
|  | ||||
|   @override | ||||
| @@ -403,8 +399,32 @@ class _PostAttachmentWidget extends StatelessWidget { | ||||
|         ? List.from(item.body['attachments']?.whereType<String>()) | ||||
|         : List.empty(); | ||||
|  | ||||
|     final unFocusColor = | ||||
|         Theme.of(context).colorScheme.onSurface.withOpacity(0.75); | ||||
|  | ||||
|     if (attachments.isEmpty) return const SizedBox.shrink(); | ||||
|  | ||||
|     if (isCompact) { | ||||
|       return Row( | ||||
|         children: [ | ||||
|           Icon( | ||||
|             Icons.file_copy, | ||||
|             size: 13, | ||||
|             color: unFocusColor, | ||||
|           ).paddingOnly(right: 5), | ||||
|           Text( | ||||
|             'attachmentHint'.trParams( | ||||
|               {'count': attachments.length.toString()}, | ||||
|             ), | ||||
|             style: TextStyle(color: unFocusColor, fontSize: 13), | ||||
|           ) | ||||
|         ], | ||||
|       ).paddingOnly( | ||||
|         left: (padding?.left ?? 0) + 17, | ||||
|         right: (padding?.right ?? 0) + 17, | ||||
|       ); | ||||
|     } | ||||
|  | ||||
|     if (attachments.length == 1 && !isLargeScreen) { | ||||
|       return AttachmentList( | ||||
|         parentId: item.id.toString(), | ||||
| @@ -422,7 +442,10 @@ class _PostAttachmentWidget extends StatelessWidget { | ||||
|         attachments: item.preload?.attachments, | ||||
|         autoload: false, | ||||
|         isGrid: true, | ||||
|       ).paddingSymmetric(horizontal: (padding?.horizontal ?? 0) + 14); | ||||
|       ).paddingOnly( | ||||
|         left: (padding?.left ?? 0) + 14, | ||||
|         right: (padding?.right ?? 0) + 14, | ||||
|       ); | ||||
|     } else if (attachments.length == 1 || isNonScrollAttachment) { | ||||
|       return AttachmentList( | ||||
|         parentId: item.id.toString(), | ||||
| @@ -430,7 +453,10 @@ class _PostAttachmentWidget extends StatelessWidget { | ||||
|         attachments: item.preload?.attachments, | ||||
|         autoload: false, | ||||
|         isColumn: true, | ||||
|       ).paddingSymmetric(horizontal: (padding?.horizontal ?? 0) + 14); | ||||
|       ).paddingOnly( | ||||
|         left: (padding?.left ?? 0) + 14, | ||||
|         right: (padding?.right ?? 0) + 14, | ||||
|       ); | ||||
|     } else { | ||||
|       return AttachmentList( | ||||
|         parentId: item.id.toString(), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user