Surface/lib/widgets/attachment/attachment_item.dart
2024-11-09 12:04:03 +08:00

26 lines
786 B
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/universal_image.dart';
class AttachmentItem extends StatelessWidget {
final SnAttachment data;
const AttachmentItem({super.key, required this.data});
@override
Widget build(BuildContext context) {
final tp = data.mimetype.split('/').firstOrNull;
final sn = context.read<SnNetworkProvider>();
switch (tp) {
case 'image':
return AspectRatio(
aspectRatio: data.metadata['ratio']?.toDouble(),
child: UniversalImage(sn.getAttachmentUrl(data.rid)),
);
default:
return const Placeholder();
}
}
}