✨ Attachment gallery
This commit is contained in:
		| @@ -5,16 +5,20 @@ import 'package:solian/services.dart'; | |||||||
|  |  | ||||||
| class AttachmentItem extends StatelessWidget { | class AttachmentItem extends StatelessWidget { | ||||||
|   final Attachment item; |   final Attachment item; | ||||||
|  |   final bool showBadge; | ||||||
|  |   final bool showHideButton; | ||||||
|  |   final BoxFit fit; | ||||||
|   final String? badge; |   final String? badge; | ||||||
|   final bool show; |   final Function? onHide; | ||||||
|   final Function onHide; |  | ||||||
|  |  | ||||||
|   const AttachmentItem({ |   const AttachmentItem({ | ||||||
|     super.key, |     super.key, | ||||||
|     required this.item, |     required this.item, | ||||||
|     required this.onHide, |  | ||||||
|     this.badge, |     this.badge, | ||||||
|     this.show = true, |     this.fit = BoxFit.cover, | ||||||
|  |     this.showBadge = true, | ||||||
|  |     this.showHideButton = true, | ||||||
|  |     this.onHide, | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
| @@ -26,9 +30,9 @@ class AttachmentItem extends StatelessWidget { | |||||||
|         children: [ |         children: [ | ||||||
|           Image.network( |           Image.network( | ||||||
|             '${ServiceFinder.services['paperclip']}/api/attachments/${item.id}', |             '${ServiceFinder.services['paperclip']}/api/attachments/${item.id}', | ||||||
|             fit: BoxFit.cover, |             fit: fit, | ||||||
|           ), |           ), | ||||||
|           if (show && badge != null) |           if (showBadge && badge != null) | ||||||
|             Positioned( |             Positioned( | ||||||
|               right: 12, |               right: 12, | ||||||
|               bottom: 8, |               bottom: 8, | ||||||
| @@ -37,7 +41,7 @@ class AttachmentItem extends StatelessWidget { | |||||||
|                 child: Chip(label: Text(badge!)), |                 child: Chip(label: Text(badge!)), | ||||||
|               ), |               ), | ||||||
|             ), |             ), | ||||||
|           if (show && item.isMature) |           if (showHideButton && item.isMature) | ||||||
|             Positioned( |             Positioned( | ||||||
|               top: 8, |               top: 8, | ||||||
|               left: 12, |               left: 12, | ||||||
| @@ -47,7 +51,9 @@ class AttachmentItem extends StatelessWidget { | |||||||
|                   visualDensity: const VisualDensity(vertical: -4, horizontal: -4), |                   visualDensity: const VisualDensity(vertical: -4, horizontal: -4), | ||||||
|                   avatar: Icon(Icons.visibility_off, color: Theme.of(context).colorScheme.onSurfaceVariant), |                   avatar: Icon(Icons.visibility_off, color: Theme.of(context).colorScheme.onSurfaceVariant), | ||||||
|                   label: Text('hide'.tr), |                   label: Text('hide'.tr), | ||||||
|                   onPressed: () => onHide(), |                   onPressed: () { | ||||||
|  |                     if (onHide != null) onHide!(); | ||||||
|  |                   }, | ||||||
|                 ), |                 ), | ||||||
|               ), |               ), | ||||||
|             ), |             ), | ||||||
|   | |||||||
| @@ -22,7 +22,7 @@ class NavShell extends StatelessWidget { | |||||||
|         centerTitle: false, |         centerTitle: false, | ||||||
|         titleSpacing: canPop ? null : 24, |         titleSpacing: canPop ? null : 24, | ||||||
|         elevation: SolianTheme.isLargeScreen(context) ? 1 : 0, |         elevation: SolianTheme.isLargeScreen(context) ? 1 : 0, | ||||||
|         leading: canPop ? BackButton() : null, |         leading: canPop ? const BackButton() : null, | ||||||
|       ), |       ), | ||||||
|       bottomNavigationBar: SolianTheme.isLargeScreen(context) ? null : const AppNavigationBottomBar(), |       bottomNavigationBar: SolianTheme.isLargeScreen(context) ? null : const AppNavigationBottomBar(), | ||||||
|       body: SolianTheme.isLargeScreen(context) |       body: SolianTheme.isLargeScreen(context) | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ import 'package:get/get.dart'; | |||||||
| import 'package:solian/models/attachment.dart'; | import 'package:solian/models/attachment.dart'; | ||||||
| import 'package:solian/providers/content/attachment_item.dart'; | import 'package:solian/providers/content/attachment_item.dart'; | ||||||
| import 'package:solian/providers/content/attachment_list.dart'; | import 'package:solian/providers/content/attachment_list.dart'; | ||||||
|  | import 'package:solian/widgets/attachments/attachment_list_fullscreen.dart'; | ||||||
|  |  | ||||||
| class AttachmentList extends StatefulWidget { | class AttachmentList extends StatefulWidget { | ||||||
|   final List<int> attachmentsId; |   final List<int> attachmentsId; | ||||||
| @@ -124,15 +125,15 @@ class _AttachmentListState extends State<AttachmentList> { | |||||||
|                 AttachmentItem( |                 AttachmentItem( | ||||||
|                   key: Key('a${element!.uuid}'), |                   key: Key('a${element!.uuid}'), | ||||||
|                   item: element, |                   item: element, | ||||||
|                   badge: _attachmentsMeta.length > 1 ? '${idx+1}/${_attachmentsMeta.length}' : null, |                   badge: _attachmentsMeta.length > 1 ? '${idx + 1}/${_attachmentsMeta.length}' : null, | ||||||
|                   show: !element.isMature || _showMature, |                   showHideButton: !element.isMature || _showMature, | ||||||
|                   onHide: () { |                   onHide: () { | ||||||
|                     setState(() => _showMature = false); |                     setState(() => _showMature = false); | ||||||
|                   }, |                   }, | ||||||
|                 ), |                 ), | ||||||
|                 if (element.isMature && !_showMature) |                 if (element.isMature && !_showMature) | ||||||
|                   BackdropFilter( |                   BackdropFilter( | ||||||
|                     filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20), |                     filter: ImageFilter.blur(sigmaX: 100, sigmaY: 100), | ||||||
|                     child: Container( |                     child: Container( | ||||||
|                       decoration: BoxDecoration( |                       decoration: BoxDecoration( | ||||||
|                         color: Colors.black.withOpacity(0.5), |                         color: Colors.black.withOpacity(0.5), | ||||||
| @@ -168,7 +169,13 @@ class _AttachmentListState extends State<AttachmentList> { | |||||||
|             if (!_showMature && _attachmentsMeta.any((e) => e!.isMature)) { |             if (!_showMature && _attachmentsMeta.any((e) => e!.isMature)) { | ||||||
|               setState(() => _showMature = true); |               setState(() => _showMature = true); | ||||||
|             } else { |             } else { | ||||||
|               // Open detail box |               Navigator.of(context, rootNavigator: true).push( | ||||||
|  |                 MaterialPageRoute( | ||||||
|  |                   builder: (context) => AttachmentListFullscreen( | ||||||
|  |                     attachment: element, | ||||||
|  |                   ), | ||||||
|  |                 ), | ||||||
|  |               ); | ||||||
|             } |             } | ||||||
|           }, |           }, | ||||||
|         ); |         ); | ||||||
|   | |||||||
							
								
								
									
										48
									
								
								lib/widgets/attachments/attachment_list_fullscreen.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								lib/widgets/attachments/attachment_list_fullscreen.dart
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | |||||||
|  | import 'package:flutter/material.dart'; | ||||||
|  | import 'package:solian/models/attachment.dart'; | ||||||
|  | import 'package:solian/providers/content/attachment_item.dart'; | ||||||
|  | import 'package:solian/services.dart'; | ||||||
|  |  | ||||||
|  | class AttachmentListFullscreen extends StatefulWidget { | ||||||
|  |   final Attachment attachment; | ||||||
|  |  | ||||||
|  |   const AttachmentListFullscreen({super.key, required this.attachment}); | ||||||
|  |  | ||||||
|  |   @override | ||||||
|  |   State<AttachmentListFullscreen> createState() => _AttachmentListFullscreenState(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | class _AttachmentListFullscreenState extends State<AttachmentListFullscreen> { | ||||||
|  |   @override | ||||||
|  |   void initState() { | ||||||
|  |     super.initState(); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   @override | ||||||
|  |   Widget build(BuildContext context) { | ||||||
|  |     return Material( | ||||||
|  |       color: Theme.of(context).colorScheme.background, | ||||||
|  |       child: GestureDetector( | ||||||
|  |         child: SizedBox( | ||||||
|  |           height: MediaQuery.of(context).size.height, | ||||||
|  |           width: MediaQuery.of(context).size.width, | ||||||
|  |           child: InteractiveViewer( | ||||||
|  |             boundaryMargin: const EdgeInsets.all(128), | ||||||
|  |             minScale: 0.1, | ||||||
|  |             maxScale: 16, | ||||||
|  |             panEnabled: true, | ||||||
|  |             scaleEnabled: true, | ||||||
|  |             child: AttachmentItem( | ||||||
|  |               showHideButton: false, | ||||||
|  |               item: widget.attachment, | ||||||
|  |               fit: BoxFit.contain, | ||||||
|  |             ), | ||||||
|  |           ), | ||||||
|  |         ), | ||||||
|  |         onTap: () { | ||||||
|  |           Navigator.pop(context); | ||||||
|  |         }, | ||||||
|  |       ), | ||||||
|  |     ); | ||||||
|  |   } | ||||||
|  | } | ||||||
| @@ -1,4 +1,3 @@ | |||||||
| import 'package:flutter/cupertino.dart'; |  | ||||||
| import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||||
| import 'package:get/get.dart'; | import 'package:get/get.dart'; | ||||||
| import 'package:solian/exts.dart'; | import 'package:solian/exts.dart'; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user