TF-2118 Handle drop n drop image as inline

(cherry picked from commit 2eb6ad6a05224b3caafc59565fd5fa6bdd819870)
This commit is contained in:
dab246
2023-09-27 19:11:43 +07:00
committed by Dat H. Pham
parent 73de2f37fa
commit 25b26acc42
6 changed files with 123 additions and 1 deletions
@@ -15,6 +15,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:html_editor_enhanced/html_editor.dart' as web_html_editor;
import 'package:http_parser/http_parser.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
@@ -1838,6 +1839,62 @@ class ComposerController extends BaseController {
onEditorFocusChange(true);
}
void handleImageUploadSuccess(
BuildContext context,
web_html_editor.FileUpload fileUpload
) {
log('ComposerController::handleImageUploadSuccess:NAME: ${fileUpload.name} | TYPE: ${fileUpload.type} | SIZE: ${fileUpload.size}');
if (fileUpload.base64 == null) {
_appToast.showToastErrorMessage(
context,
AppLocalizations.of(context).can_not_upload_this_file_as_attachments
);
return;
}
if (fileUpload.type == null) {
return;
}
final mediaType = MediaType.parse(fileUpload.type!);
if (mediaType.isImageValid()) {
_addInlineImageFromDragAndDrop(
base64Data: fileUpload.base64!,
name: fileUpload.name,
type: mediaType,
size: fileUpload.size,
);
}
}
void _addInlineImageFromDragAndDrop({
required String base64Data,
String? name,
MediaType? type,
int? size
}) {
log('ComposerController::_addInlineImageFromDragAndDrop:name: $name');
richTextWebController.insertInlineImage(
base64Data: base64Data,
name: name,
type: type,
size: size,
);
}
void handleImageUploadFailure({
required BuildContext context,
required web_html_editor.UploadError uploadError,
web_html_editor.FileUpload? fileUpload,
String? base64Str,
}) {
logError('ComposerController::handleImageUploadFailure:fileUpload: $fileUpload | uploadError: $uploadError');
_appToast.showToastErrorMessage(
context,
'${AppLocalizations.of(context).can_not_upload_this_file_as_attachments}. (${uploadError.name})'
);
}
FocusNode? getNextFocusOfToEmailAddress() {
if (ccRecipientState.value == PrefixRecipientState.enabled) {
return ccAddressFocusNode;