2024-11-10 09:21:57 +00:00
|
|
|
import 'package:dismissible_page/dismissible_page.dart';
|
2024-11-09 04:04:03 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:surface/providers/sn_network.dart';
|
|
|
|
import 'package:surface/types/attachment.dart';
|
2024-11-10 09:21:57 +00:00
|
|
|
import 'package:surface/widgets/attachment/attachment_detail.dart';
|
2024-11-09 04:04:03 +00:00
|
|
|
import 'package:surface/widgets/universal_image.dart';
|
2024-11-10 09:21:57 +00:00
|
|
|
import 'package:uuid/uuid.dart';
|
2024-11-09 04:04:03 +00:00
|
|
|
|
|
|
|
class AttachmentItem extends StatelessWidget {
|
|
|
|
final SnAttachment data;
|
2024-11-10 09:21:57 +00:00
|
|
|
final bool isExpandable;
|
|
|
|
const AttachmentItem({
|
|
|
|
super.key,
|
|
|
|
required this.data,
|
|
|
|
this.isExpandable = false,
|
|
|
|
});
|
2024-11-09 04:04:03 +00:00
|
|
|
|
2024-11-10 09:21:57 +00:00
|
|
|
Widget _buildContent(BuildContext context, String heroTag) {
|
2024-11-09 04:04:03 +00:00
|
|
|
final tp = data.mimetype.split('/').firstOrNull;
|
|
|
|
final sn = context.read<SnNetworkProvider>();
|
|
|
|
switch (tp) {
|
|
|
|
case 'image':
|
2024-11-10 09:21:57 +00:00
|
|
|
return Hero(
|
|
|
|
tag: 'attachment-${data.rid}-$heroTag',
|
|
|
|
child: UniversalImage(
|
|
|
|
sn.getAttachmentUrl(data.rid),
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
),
|
2024-11-09 04:04:03 +00:00
|
|
|
);
|
|
|
|
default:
|
|
|
|
return const Placeholder();
|
|
|
|
}
|
|
|
|
}
|
2024-11-10 09:21:57 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final uuid = Uuid();
|
|
|
|
final heroTag = uuid.v4();
|
|
|
|
|
|
|
|
if (isExpandable) {
|
|
|
|
return GestureDetector(
|
|
|
|
child: _buildContent(context, heroTag),
|
|
|
|
onTap: () {
|
|
|
|
context.pushTransparentRoute(
|
|
|
|
AttachmentDetailPopup(data: data, heroTag: heroTag),
|
|
|
|
rootNavigator: true,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _buildContent(context, heroTag);
|
|
|
|
}
|
2024-11-09 04:04:03 +00:00
|
|
|
}
|