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:core/utils/app_logger.dart';
|
||||||
import 'package:file_picker/file_picker.dart';
|
import 'package:file_picker/file_picker.dart';
|
||||||
import 'package:rich_text_composer/rich_text_composer.dart';
|
import 'package:rich_text_composer/rich_text_composer.dart';
|
||||||
@@ -32,15 +34,20 @@ class RichTextMobileTabletController extends BaseRichTextController {
|
|||||||
htmlEditorApi?.formatHeader(styleSelected.styleValue);
|
htmlEditorApi?.formatHeader(styleSelected.styleValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertImageAsBase64({required PlatformFile platformFile, int? maxWidth}) async {
|
void insertImageData({required PlatformFile platformFile, int? maxWidth}) async {
|
||||||
if (platformFile.bytes != null) {
|
try {
|
||||||
await htmlEditorApi?.insertImageData(
|
if (platformFile.path?.isNotEmpty == true) {
|
||||||
platformFile.bytes!,
|
final bytesData = await File(platformFile.path!).readAsBytes();
|
||||||
'image/${platformFile.extension}',
|
await htmlEditorApi?.insertImageData(
|
||||||
maxWidth: maxWidth
|
bytesData,
|
||||||
);
|
'image/${platformFile.extension}',
|
||||||
} else {
|
maxWidth: maxWidth
|
||||||
logError("RichTextWebController::insertImageAsBase64: bytes is null");
|
);
|
||||||
|
} 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(
|
final filePickerResult = await FilePicker.platform.pickFiles(
|
||||||
type: FileType.image,
|
type: FileType.image,
|
||||||
withData: true
|
withData: PlatformInfo.isWeb
|
||||||
);
|
);
|
||||||
|
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
final platformFile = filePickerResult?.files.single;
|
if (filePickerResult?.files.isNotEmpty == true) {
|
||||||
if (platformFile != null) {
|
final platformFile = filePickerResult!.files.first;
|
||||||
_insertInlineImage(context, platformFile, maxWidth: maxWidth);
|
_insertInlineImage(context, platformFile, maxWidth: maxWidth);
|
||||||
} else {
|
} else {
|
||||||
_appToast.showToastErrorMessage(
|
_appToast.showToastErrorMessage(
|
||||||
@@ -515,7 +515,7 @@ class IdentityCreatorController extends BaseController {
|
|||||||
if (PlatformInfo.isWeb) {
|
if (PlatformInfo.isWeb) {
|
||||||
richTextWebController.insertImageAsBase64(platformFile: platformFile);
|
richTextWebController.insertImageAsBase64(platformFile: platformFile);
|
||||||
} else if (PlatformInfo.isMobile) {
|
} else if (PlatformInfo.isMobile) {
|
||||||
richTextMobileTabletController.insertImageAsBase64(platformFile: platformFile, maxWidth: maxWidth);
|
richTextMobileTabletController.insertImageData(platformFile: platformFile, maxWidth: maxWidth);
|
||||||
} else {
|
} else {
|
||||||
logError("IdentityCreatorController::_insertInlineImage: Platform not supported");
|
logError("IdentityCreatorController::_insertInlineImage: Platform not supported");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user