chat support download updated
This commit is contained in:
@@ -1,99 +1,118 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../services/dio_client.dart';
|
||||
import '../screens/chat_file_viewer.dart';
|
||||
import '../widgets/chat_file_actions.dart';
|
||||
|
||||
class ChatFilePreview extends StatelessWidget {
|
||||
final String filePath;
|
||||
final String fileType;
|
||||
final bool isUser;
|
||||
|
||||
final bool isLocal;
|
||||
|
||||
const ChatFilePreview({
|
||||
super.key,
|
||||
required this.filePath,
|
||||
required this.fileType,
|
||||
required this.isUser,
|
||||
this.isLocal = false,
|
||||
});
|
||||
|
||||
|
||||
@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,
|
||||
),
|
||||
),
|
||||
// LOCAL IMAGE (uploading preview)
|
||||
if (isLocal && fileType.startsWith('image/')) {
|
||||
return Image.file(
|
||||
File(filePath),
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
// ✅ TAP = OPEN
|
||||
ChatFileViewer.open(
|
||||
context,
|
||||
url: url,
|
||||
fileType: fileType,
|
||||
);
|
||||
},
|
||||
onLongPress: () {
|
||||
// ✅ LONG PRESS = OPEN / DOWNLOAD
|
||||
ChatFileActions.show(
|
||||
context,
|
||||
url: url,
|
||||
fileType: fileType,
|
||||
);
|
||||
},
|
||||
child: _buildPreviewUI(textColor, url),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPreviewUI(Color textColor, String url) {
|
||||
// IMAGE
|
||||
if (fileType.startsWith('image/')) {
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Image.network(
|
||||
url,
|
||||
width: 180,
|
||||
height: 120,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// VIDEO
|
||||
if (fileType.startsWith('video/')) {
|
||||
return 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 / OTHER FILES
|
||||
return 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;
|
||||
|
||||
Reference in New Issue
Block a user