109 lines
2.7 KiB
Dart
109 lines
2.7 KiB
Dart
|
|
import 'package:flutter/material.dart';
|
||
|
|
import '../services/dio_client.dart';
|
||
|
|
import '../screens/chat_file_viewer.dart';
|
||
|
|
|
||
|
|
class ChatFilePreview extends StatelessWidget {
|
||
|
|
final String filePath;
|
||
|
|
final String fileType;
|
||
|
|
final bool isUser;
|
||
|
|
|
||
|
|
const ChatFilePreview({
|
||
|
|
super.key,
|
||
|
|
required this.filePath,
|
||
|
|
required this.fileType,
|
||
|
|
required this.isUser,
|
||
|
|
});
|
||
|
|
|
||
|
|
@override
|
||
|
|
Widget build(BuildContext context) {
|
||
|
|
final url = "${DioClient.baseUrl}/storage/$filePath";
|
||
|
|
final textColor = isUser ? Colors.white : Colors.black;
|
||
|
|
|
||
|
|
// IMAGE PREVIEW
|
||
|
|
if (fileType.startsWith('image/')) {
|
||
|
|
return GestureDetector(
|
||
|
|
onTap: () => ChatFileViewer.open(
|
||
|
|
context,
|
||
|
|
url: url,
|
||
|
|
fileType: fileType,
|
||
|
|
),
|
||
|
|
child: ClipRRect(
|
||
|
|
borderRadius: BorderRadius.circular(8),
|
||
|
|
child: Image.network(
|
||
|
|
url,
|
||
|
|
width: 180,
|
||
|
|
height: 120,
|
||
|
|
fit: BoxFit.cover,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
// VIDEO PREVIEW
|
||
|
|
if (fileType.startsWith('video/')) {
|
||
|
|
return GestureDetector(
|
||
|
|
onTap: () => ChatFileViewer.open(
|
||
|
|
context,
|
||
|
|
url: url,
|
||
|
|
fileType: fileType,
|
||
|
|
),
|
||
|
|
child: Stack(
|
||
|
|
alignment: Alignment.center,
|
||
|
|
children: [
|
||
|
|
Container(
|
||
|
|
width: 180,
|
||
|
|
height: 120,
|
||
|
|
decoration: BoxDecoration(
|
||
|
|
color: Colors.black26,
|
||
|
|
borderRadius: BorderRadius.circular(8),
|
||
|
|
),
|
||
|
|
child: const Icon(
|
||
|
|
Icons.videocam,
|
||
|
|
size: 50,
|
||
|
|
color: Colors.white70,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
const Icon(
|
||
|
|
Icons.play_circle_fill,
|
||
|
|
size: 56,
|
||
|
|
color: Colors.white,
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
// PDF / FILE PREVIEW
|
||
|
|
return GestureDetector(
|
||
|
|
onTap: () => ChatFileViewer.open(
|
||
|
|
context,
|
||
|
|
url: url,
|
||
|
|
fileType: fileType,
|
||
|
|
),
|
||
|
|
child: Row(
|
||
|
|
mainAxisSize: MainAxisSize.min,
|
||
|
|
children: [
|
||
|
|
Icon(_fileIcon(fileType), color: textColor),
|
||
|
|
const SizedBox(width: 8),
|
||
|
|
Text(
|
||
|
|
_fileLabel(fileType),
|
||
|
|
style: TextStyle(color: textColor),
|
||
|
|
),
|
||
|
|
],
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
IconData _fileIcon(String type) {
|
||
|
|
if (type == 'application/pdf') return Icons.picture_as_pdf;
|
||
|
|
if (type.contains('excel')) return Icons.table_chart;
|
||
|
|
return Icons.insert_drive_file;
|
||
|
|
}
|
||
|
|
|
||
|
|
String _fileLabel(String type) {
|
||
|
|
if (type == 'application/pdf') return "PDF document";
|
||
|
|
if (type.contains('excel')) return "Excel file";
|
||
|
|
return "Download file";
|
||
|
|
}
|
||
|
|
}
|