sendMultiFileMessage method

Future<void> sendMultiFileMessage({
  1. required String id,
  2. required String channelName,
  3. required String messageType,
  4. required List<File?> files,
})

Implementation

Future<void> sendMultiFileMessage({
  required String id,
  required String channelName,
  required String messageType,
  required List<File?> files,
}) async {
  for (var element in files) {
    ConversationMessage unsentMessage = ConversationMessage(
      message: element?.path,
      messageType: messageType,
      uid: id,
      messageFrom: 'company',
      timestamp: DateTime.now().toString(),
      platform: 'Bodsquare platform',
      createdAt: DateTime.now(),
      status: 'offline',
    );
    //log(element!.path);
    await addOfflineMessage(unsentMessage).then((value) => update);
  }

  if (files[0] != null) {
    var ff = files[0]?.path.contains('file:///');
    if (ff == true) {
      files[0] = File(files[0]!.path.replaceFirst('file://', ''));
    }
  }

  isLoading.value = true;
  var imageUrlList = await uploadMultiCloudinaryImages(files);
  for (var imageUrl in imageUrlList) {
    await sendFileMessage(
        id: id,
        message: imageUrl.secureUrl,
        messageType: messageType,
        channelName: channelName);
    isLoading.value = false;
  }
}