Attachment gallery

This commit is contained in:
LittleSheep 2024-05-21 00:02:39 +08:00
parent 2ec9cd814d
commit 158f189531
5 changed files with 74 additions and 14 deletions

View File

@ -5,16 +5,20 @@ import 'package:solian/services.dart';
class AttachmentItem extends StatelessWidget {
final Attachment item;
final bool showBadge;
final bool showHideButton;
final BoxFit fit;
final String? badge;
final bool show;
final Function onHide;
final Function? onHide;
const AttachmentItem({
super.key,
required this.item,
required this.onHide,
this.badge,
this.show = true,
this.fit = BoxFit.cover,
this.showBadge = true,
this.showHideButton = true,
this.onHide,
});
@override
@ -26,9 +30,9 @@ class AttachmentItem extends StatelessWidget {
children: [
Image.network(
'${ServiceFinder.services['paperclip']}/api/attachments/${item.id}',
fit: BoxFit.cover,
fit: fit,
),
if (show && badge != null)
if (showBadge && badge != null)
Positioned(
right: 12,
bottom: 8,
@ -37,7 +41,7 @@ class AttachmentItem extends StatelessWidget {
child: Chip(label: Text(badge!)),
),
),
if (show && item.isMature)
if (showHideButton && item.isMature)
Positioned(
top: 8,
left: 12,
@ -47,7 +51,9 @@ class AttachmentItem extends StatelessWidget {
visualDensity: const VisualDensity(vertical: -4, horizontal: -4),
avatar: Icon(Icons.visibility_off, color: Theme.of(context).colorScheme.onSurfaceVariant),
label: Text('hide'.tr),
onPressed: () => onHide(),
onPressed: () {
if (onHide != null) onHide!();
},
),
),
),

View File

@ -22,7 +22,7 @@ class NavShell extends StatelessWidget {
centerTitle: false,
titleSpacing: canPop ? null : 24,
elevation: SolianTheme.isLargeScreen(context) ? 1 : 0,
leading: canPop ? BackButton() : null,
leading: canPop ? const BackButton() : null,
),
bottomNavigationBar: SolianTheme.isLargeScreen(context) ? null : const AppNavigationBottomBar(),
body: SolianTheme.isLargeScreen(context)

View File

@ -6,6 +6,7 @@ import 'package:get/get.dart';
import 'package:solian/models/attachment.dart';
import 'package:solian/providers/content/attachment_item.dart';
import 'package:solian/providers/content/attachment_list.dart';
import 'package:solian/widgets/attachments/attachment_list_fullscreen.dart';
class AttachmentList extends StatefulWidget {
final List<int> attachmentsId;
@ -125,14 +126,14 @@ class _AttachmentListState extends State<AttachmentList> {
key: Key('a${element!.uuid}'),
item: element,
badge: _attachmentsMeta.length > 1 ? '${idx + 1}/${_attachmentsMeta.length}' : null,
show: !element.isMature || _showMature,
showHideButton: !element.isMature || _showMature,
onHide: () {
setState(() => _showMature = false);
},
),
if (element.isMature && !_showMature)
BackdropFilter(
filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20),
filter: ImageFilter.blur(sigmaX: 100, sigmaY: 100),
child: Container(
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
@ -168,7 +169,13 @@ class _AttachmentListState extends State<AttachmentList> {
if (!_showMature && _attachmentsMeta.any((e) => e!.isMature)) {
setState(() => _showMature = true);
} else {
// Open detail box
Navigator.of(context, rootNavigator: true).push(
MaterialPageRoute(
builder: (context) => AttachmentListFullscreen(
attachment: element,
),
),
);
}
},
);

View 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);
},
),
);
}
}

View File

@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:solian/exts.dart';