Skip to content

Commit

Permalink
TF-2245 Only use bytes when insert image in identity creator on web
Browse files Browse the repository at this point in the history
Signed-off-by: dab246 <tdvu@linagora.com>
  • Loading branch information
dab246 committed Oct 24, 2023
1 parent 74f7322 commit c016e5f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit c016e5f

Please sign in to comment.