chat support download updated

This commit is contained in:
Abhishek Mali
2025-12-18 11:03:25 +05:30
parent bbde34fae4
commit b9fb9455e7
11 changed files with 416 additions and 131 deletions

View File

@@ -24,27 +24,25 @@ class ChatService {
Future<void> sendMessage(
int ticketId, {
String? message,
String? filePath,
String? clientId,
}) async {
final form = FormData();
if (message != null) form.fields.add(MapEntry('message', message));
if (filePath != null) {
form.files.add(
MapEntry(
'file',
await MultipartFile.fromFile(filePath),
),
);
}
if (clientId != null) form.fields.add(MapEntry('client_id', clientId));
await dio.post('/user/chat/send/$ticketId', data: form);
}
// ---------------------------
// SEND FILE (image/video/pdf/excel)
// ---------------------------
Future<void> sendFile(int ticketId, File file) async {
Future<Map<String, dynamic>> sendFile(
int ticketId,
File file, {
required Function(double) onProgress,
}) async {
final formData = FormData.fromMap({
'file': await MultipartFile.fromFile(
file.path,
@@ -52,13 +50,20 @@ class ChatService {
),
});
await dio.post(
final res = await dio.post(
"/user/chat/send/$ticketId",
data: formData,
options: Options(
headers: {'Content-Type': 'multipart/form-data'},
),
onSendProgress: (sent, total) {
if (total > 0) {
onProgress(sent / total);
}
},
);
return Map<String, dynamic>.from(res.data['message']);
}
}