sendMedia method
Implementation
sendMedia(BuildContext context) async {
debugPrint("send media");
// var previousRoute = Get.previousRoute;
// if (await AppUtils.isNetConnected()) {
Platform.isIOS
? Helper.showLoading(
message: AppConstants.compressingFiles, buildContext: context)
: Helper.progressLoading(context: context);
var featureNotAvailable = false;
try {
int i = 0;
await Future.forEach(filePath, (data) async {
debugPrint(data.type);
if (data.type == 'image') {
if (!availableFeatures.value.isImageAttachmentAvailable.checkNull()) {
featureNotAvailable = true;
return false;
}
debugPrint("sending image");
var response = await Get.find<ChatController>().sendImageMessage(
data.path, captionMessage[i], Constants.emptyString, context);
debugPrint("Preview View ==> $response");
if (response != null) {
debugPrint("Image send Success");
}
} else if (data.type == 'video') {
if (!availableFeatures.value.isVideoAttachmentAvailable.checkNull()) {
featureNotAvailable = true;
return false;
}
debugPrint("sending video");
var response = await Get.find<ChatController>().sendVideoMessage(
data.path!, captionMessage[i], Constants.emptyString, context);
debugPrint("Preview View ==> $response");
if (response != null) {
debugPrint("Video send Success");
}
}
i++;
});
} finally {
if (context.mounted) Helper.hideLoading(context: context);
if (!featureNotAvailable) {
if (isFromGalleryPicker) {
// Get.back();
if (context.mounted) Navigator.pop(context);
}
// Get.back();
if (context.mounted) Navigator.pop(context);
} else {
if (context.mounted) Helper.showFeatureUnavailable(context);
}
}
}