Skip to content

Commit

Permalink
fixup! TF-1486 Add insert image in signature on mobile/tablet
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Jul 13, 2023
1 parent 184ad43 commit 4213f3b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

extension SizeExtension on int {

int get kiloByteToBytes => this * 1024;
int get toBytes => this * 1024;
}
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class IdentityCreatorController extends BaseController {
}
}

void pickImage(BuildContext context, {int? maxWith}) async {
void pickImage(BuildContext context, {int? maxWidth}) async {
clearFocusEditor(context);

final filePickerResult = await FilePicker.platform.pickFiles(
Expand All @@ -484,7 +484,7 @@ class IdentityCreatorController extends BaseController {
if (context.mounted) {
final platformFile = filePickerResult?.files.single;
if (platformFile != null) {
_insertInlineImage(context, platformFile, maxWith: maxWith);
_insertInlineImage(context, platformFile, maxWidth: maxWidth);
} else {
_appToast.showToastErrorMessage(
context,
Expand All @@ -497,25 +497,25 @@ class IdentityCreatorController extends BaseController {
}

bool _isExceedMaxSizeInlineImage(int fileSize) =>
fileSize > IdentityCreatorConstants.maxSizeIdentityInlineImage.kiloByteToBytes;
fileSize > IdentityCreatorConstants.maxKBSizeIdentityInlineImage.toBytes;

void _insertInlineImage(
BuildContext context,
PlatformFile platformFile,
{int? maxWith}
{int? maxWidth}
) {
if (_isExceedMaxSizeInlineImage(platformFile.size)) {
_appToast.showToastErrorMessage(
context,
AppLocalizations.of(context).pleaseChooseAnImageSizeCorrectly(
IdentityCreatorConstants.maxSizeIdentityInlineImage
IdentityCreatorConstants.maxKBSizeIdentityInlineImage
)
);
} else {
if (PlatformInfo.isWeb) {
richTextWebController.insertImageAsBase64(platformFile: platformFile);
} else if (PlatformInfo.isMobile) {
richTextMobileTabletController.insertImageAsBase64(platformFile: platformFile, maxWidth: maxWith);
richTextMobileTabletController.insertImageAsBase64(platformFile: platformFile, maxWidth: maxWidth);
} else {
logError("IdentityCreatorController::_insertInlineImage: Platform not supported");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class IdentityCreatorView extends GetWidget<IdentityCreatorController>
titleBackgroundBottomSheet: AppLocalizations.of(context).titleBackground,
titleForegroundBottomSheet: AppLocalizations.of(context).titleForeground,
titleFormatBottomSheet: AppLocalizations.of(context).titleFormat,
insertImage: () => controller.pickImage(context, maxWith: _getMaxWidth(context).toInt()),
insertImage: () => controller.pickImage(context, maxWidth: _getMaxWidth(context).toInt()),
),
richTextController: controller.keyboardRichTextController,
paddingChild: EdgeInsets.zero,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

class IdentityCreatorConstants {
static const int maxSizeIdentityInlineImage = 16; // Kilobyte
static const int maxKBSizeIdentityInlineImage = 16; // Kilobyte
}

0 comments on commit 4213f3b

Please sign in to comment.