TF-2245 Only use bytes when insert image in identity creator on web
Signed-off-by: dab246 <tdvu@linagora.com> (cherry picked from commit d879dbaf7e9fbe81c7cf1c1e43b1ec275e3522c6)
This commit is contained in:
+16
-9
@@ -1,3 +1,5 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:rich_text_composer/rich_text_composer.dart';
|
||||
@@ -32,15 +34,20 @@ class RichTextMobileTabletController extends BaseRichTextController {
|
||||
htmlEditorApi?.formatHeader(styleSelected.styleValue);
|
||||
}
|
||||
|
||||
void insertImageAsBase64({required PlatformFile platformFile, int? maxWidth}) async {
|
||||
if (platformFile.bytes != null) {
|
||||
await htmlEditorApi?.insertImageData(
|
||||
platformFile.bytes!,
|
||||
'image/${platformFile.extension}',
|
||||
maxWidth: maxWidth
|
||||
);
|
||||
} else {
|
||||
logError("RichTextWebController::insertImageAsBase64: bytes is null");
|
||||
void insertImageData({required PlatformFile platformFile, int? maxWidth}) async {
|
||||
try {
|
||||
if (platformFile.path?.isNotEmpty == true) {
|
||||
final bytesData = await File(platformFile.path!).readAsBytes();
|
||||
await htmlEditorApi?.insertImageData(
|
||||
bytesData,
|
||||
'image/${platformFile.extension}',
|
||||
maxWidth: maxWidth
|
||||
);
|
||||
} else {
|
||||
logError('RichTextMobileTabletController::insertImageData: path is null');
|
||||
}
|
||||
} catch (e) {
|
||||
logError('RichTextMobileTabletController::insertImageData:Exception: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,12 +478,12 @@ class IdentityCreatorController extends BaseController {
|
||||
|
||||
final filePickerResult = await FilePicker.platform.pickFiles(
|
||||
type: FileType.image,
|
||||
withData: true
|
||||
withData: PlatformInfo.isWeb
|
||||
);
|
||||
|
||||
if (context.mounted) {
|
||||
final platformFile = filePickerResult?.files.single;
|
||||
if (platformFile != null) {
|
||||
if (filePickerResult?.files.isNotEmpty == true) {
|
||||
final platformFile = filePickerResult!.files.first;
|
||||
_insertInlineImage(context, platformFile, maxWidth: maxWidth);
|
||||
} else {
|
||||
_appToast.showToastErrorMessage(
|
||||
@@ -515,7 +515,7 @@ class IdentityCreatorController extends BaseController {
|
||||
if (PlatformInfo.isWeb) {
|
||||
richTextWebController.insertImageAsBase64(platformFile: platformFile);
|
||||
} else if (PlatformInfo.isMobile) {
|
||||
richTextMobileTabletController.insertImageAsBase64(platformFile: platformFile, maxWidth: maxWidth);
|
||||
richTextMobileTabletController.insertImageData(platformFile: platformFile, maxWidth: maxWidth);
|
||||
} else {
|
||||
logError("IdentityCreatorController::_insertInlineImage: Platform not supported");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user