✨ Detailed attachments
This commit is contained in:
@ -1,25 +1,55 @@
|
||||
import 'package:dismissible_page/dismissible_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:surface/providers/sn_network.dart';
|
||||
import 'package:surface/types/attachment.dart';
|
||||
import 'package:surface/widgets/attachment/attachment_detail.dart';
|
||||
import 'package:surface/widgets/universal_image.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class AttachmentItem extends StatelessWidget {
|
||||
final SnAttachment data;
|
||||
const AttachmentItem({super.key, required this.data});
|
||||
final bool isExpandable;
|
||||
const AttachmentItem({
|
||||
super.key,
|
||||
required this.data,
|
||||
this.isExpandable = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget _buildContent(BuildContext context, String heroTag) {
|
||||
final tp = data.mimetype.split('/').firstOrNull;
|
||||
final sn = context.read<SnNetworkProvider>();
|
||||
switch (tp) {
|
||||
case 'image':
|
||||
return UniversalImage(
|
||||
sn.getAttachmentUrl(data.rid),
|
||||
fit: BoxFit.cover,
|
||||
return Hero(
|
||||
tag: 'attachment-${data.rid}-$heroTag',
|
||||
child: UniversalImage(
|
||||
sn.getAttachmentUrl(data.rid),
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
);
|
||||
default:
|
||||
return const Placeholder();
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user