Solian/lib/widgets/attachments/attachment_item.dart

65 lines
1.7 KiB
Dart
Raw Normal View History

2024-05-18 14:23:36 +00:00
import 'package:flutter/material.dart';
2024-05-20 15:39:23 +00:00
import 'package:get/get.dart';
2024-05-18 14:23:36 +00:00
import 'package:solian/models/attachment.dart';
import 'package:solian/services.dart';
class AttachmentItem extends StatelessWidget {
final Attachment item;
2024-05-20 16:02:39 +00:00
final bool showBadge;
final bool showHideButton;
final BoxFit fit;
2024-05-20 15:39:23 +00:00
final String? badge;
2024-05-20 16:02:39 +00:00
final Function? onHide;
2024-05-18 14:23:36 +00:00
2024-05-20 15:39:23 +00:00
const AttachmentItem({
super.key,
required this.item,
this.badge,
2024-05-20 16:02:39 +00:00
this.fit = BoxFit.cover,
this.showBadge = true,
this.showHideButton = true,
this.onHide,
2024-05-20 15:39:23 +00:00
});
2024-05-18 14:23:36 +00:00
@override
Widget build(BuildContext context) {
return Hero(
tag: Key('a${item.uuid}'),
2024-05-20 15:39:23 +00:00
child: Stack(
fit: StackFit.expand,
children: [
Image.network(
'${ServiceFinder.services['paperclip']}/api/attachments/${item.id}',
2024-05-20 16:02:39 +00:00
fit: fit,
2024-05-20 15:39:23 +00:00
),
2024-05-20 16:02:39 +00:00
if (showBadge && badge != null)
2024-05-20 15:39:23 +00:00
Positioned(
right: 12,
bottom: 8,
child: Material(
color: Colors.transparent,
child: Chip(label: Text(badge!)),
),
),
2024-05-20 16:02:39 +00:00
if (showHideButton && item.isMature)
2024-05-20 15:39:23 +00:00
Positioned(
top: 8,
left: 12,
child: Material(
color: Colors.transparent,
child: ActionChip(
visualDensity: const VisualDensity(vertical: -4, horizontal: -4),
avatar: Icon(Icons.visibility_off, color: Theme.of(context).colorScheme.onSurfaceVariant),
label: Text('hide'.tr),
2024-05-20 16:02:39 +00:00
onPressed: () {
if (onHide != null) onHide!();
},
2024-05-20 15:39:23 +00:00
),
),
),
],
2024-05-18 14:23:36 +00:00
),
);
}
2024-05-20 15:39:23 +00:00
}