Skip to content

Commit

Permalink
TF-1301 Handle select font size while compose email
Browse files Browse the repository at this point in the history
Signed-off-by: dab246 <[email protected]>

Signed-off-by: dab246 <[email protected]>
  • Loading branch information
dab246 authored and hoangdat committed Oct 17, 2023
1 parent 1aee8b4 commit 194ccd3
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 172 deletions.
7 changes: 3 additions & 4 deletions lib/features/composer/presentation/composer_view_web.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:core/presentation/resources/image_paths.dart';
import 'package:core/presentation/utils/responsive_utils.dart';
import 'package:core/presentation/views/responsive/responsive_widget.dart';
import 'package:core/utils/app_logger.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
Expand Down Expand Up @@ -150,7 +149,6 @@ class ComposerView extends GetWidget<ComposerController> {
),
Expanded(
child: LayoutBuilder(builder: (context, constraints) {
log('ComposerView::build:mobile:constraints: $constraints');
return Stack(
children: [
Padding(
Expand All @@ -175,6 +173,7 @@ class ComposerView extends GetWidget<ComposerController> {
base64Str: base64Str,
);
},
onEditorTextSizeChanged: controller.richTextWebController.onEditorTextSizeChanged,
width: constraints.maxWidth,
height: constraints.maxHeight,
)),
Expand Down Expand Up @@ -330,7 +329,6 @@ class ComposerView extends GetWidget<ComposerController> {
color: ComposerStyle.backgroundEditorColor
),
child: LayoutBuilder(builder: (context, constraints) {
log('ComposerView::build:desktop:constraints: $constraints');
return Stack(
children: [
Column(
Expand Down Expand Up @@ -361,6 +359,7 @@ class ComposerView extends GetWidget<ComposerController> {
base64Str: base64Str,
);
},
onEditorTextSizeChanged: controller.richTextWebController.onEditorTextSizeChanged,
width: constraints.maxWidth,
height: constraints.maxHeight,
),
Expand Down Expand Up @@ -551,7 +550,6 @@ class ComposerView extends GetWidget<ComposerController> {
color: ComposerStyle.backgroundEditorColor
),
child: LayoutBuilder(builder: (context, constraints) {
log('ComposerView::build:tablet:constraints: $constraints');
return Stack(
children: [
Column(
Expand Down Expand Up @@ -579,6 +577,7 @@ class ComposerView extends GetWidget<ComposerController> {
base64Str: base64Str,
);
},
onEditorTextSizeChanged: controller.richTextWebController.onEditorTextSizeChanged,
width: constraints.maxWidth,
height: constraints.maxHeight,
)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';

class RichTextWebController extends BaseRichTextController {

static const List<int> fontSizeList = [10, 12, 14, 15, 16, 18, 24, 36, 48, 64];
static const int fontSizeDefault = 16;

final editorController = HtmlEditorController();

final listTextStyleApply = RxList<RichTextStyleType>();
final selectedTextColor = Colors.black.obs;
final selectedTextBackgroundColor = Colors.white.obs;
final selectedFontName = FontNameType.sansSerif.obs;
final selectedFontSize = RxInt(fontSizeDefault);
final codeViewState = CodeViewState.disabled.obs;
final selectedParagraph = ParagraphType.alignLeft.obs;
final selectedOrderList = OrderListType.bulletedList.obs;
Expand Down Expand Up @@ -61,6 +65,10 @@ class RichTextWebController extends BaseRichTextController {
_updateParagraph(settings);
}

void onEditorTextSizeChanged(int? size) {
_updateFontSize(size);
}

void _updateTextStyle(EditorSettings settings) {
listTextStyleApply.clear();

Expand Down Expand Up @@ -92,11 +100,20 @@ class RichTextWebController extends BaseRichTextController {
}
}

void _updateFontSize(int? size) {
log('RichTextWebController::_updateFontSize():size: $size');
if (size != null && fontSizeList.contains(size)) {
selectedFontSize.value = size;
}
}

void _updateTextColor(EditorSettings settings) {
log('RichTextWebController::_updateTextColor():foregroundColor: ${settings.foregroundColor}');
selectedTextColor.value = settings.foregroundColor;
}

void _updateBackgroundTextColor(EditorSettings settings) {
log('RichTextWebController::_updateBackgroundTextColor():backgroundColor: ${settings.backgroundColor}');
selectedTextBackgroundColor.value = settings.backgroundColor;
}

Expand Down Expand Up @@ -199,6 +216,11 @@ class RichTextWebController extends BaseRichTextController {
value: fontSelected.value);
}

void applyNewFontSize(int? newSize) {
selectedFontSize.value = newSize ?? fontSizeDefault;
editorController.setFontSize(newSize ?? fontSizeDefault);
}

bool get isMenuFontOpen => menuFontStatus.value == DropdownMenuFontStatus.open;

bool get isMenuHeaderStyleOpen => menuHeaderStyleStatus.value == DropdownMenuFontStatus.open;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import 'package:flutter/material.dart';

class ToolbarRichTextBuilderStyle {
static const double itemHorizontalSpace = 8.0;
static const double itemVerticalSpace = 8.0;

static const EdgeInsetsGeometry padding = EdgeInsetsDirectional.only(start: 20, top: 8, bottom: 8);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
final OnEditorSettingsChange? onEditorSettings;
final OnImageUploadSuccessAction? onImageUploadSuccessAction;
final OnImageUploadFailureAction? onImageUploadFailureAction;
final OnEditorTextSizeChanged? onEditorTextSizeChanged;
final double? width;
final double? height;

Expand All @@ -45,6 +46,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
this.onEditorSettings,
this.onImageUploadSuccessAction,
this.onImageUploadFailureAction,
this.onEditorTextSizeChanged,
this.width,
this.height,
});
Expand All @@ -71,6 +73,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
onEditorSettings: onEditorSettings,
onImageUploadSuccessAction: onImageUploadSuccessAction,
onImageUploadFailureAction: onImageUploadFailureAction,
onEditorTextSizeChanged: onEditorTextSizeChanged,
width: width,
height: height,
);
Expand All @@ -94,6 +97,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
onEditorSettings: onEditorSettings,
onImageUploadSuccessAction: onImageUploadSuccessAction,
onImageUploadFailureAction: onImageUploadFailureAction,
onEditorTextSizeChanged: onEditorTextSizeChanged,
width: width,
height: height,
),
Expand All @@ -119,6 +123,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
onEditorSettings: onEditorSettings,
onImageUploadSuccessAction: onImageUploadSuccessAction,
onImageUploadFailureAction: onImageUploadFailureAction,
onEditorTextSizeChanged: onEditorTextSizeChanged,
width: width,
height: height,
);
Expand Down Expand Up @@ -151,6 +156,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
onEditorSettings: onEditorSettings,
onImageUploadSuccessAction: onImageUploadSuccessAction,
onImageUploadFailureAction: onImageUploadFailureAction,
onEditorTextSizeChanged: onEditorTextSizeChanged,
width: width,
height: height,
);
Expand Down Expand Up @@ -179,6 +185,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
onEditorSettings: onEditorSettings,
onImageUploadSuccessAction: onImageUploadSuccessAction,
onImageUploadFailureAction: onImageUploadFailureAction,
onEditorTextSizeChanged: onEditorTextSizeChanged,
width: width,
height: height,
);
Expand All @@ -198,6 +205,7 @@ class WebEditorView extends StatelessWidget with EditorViewMixin {
onEditorSettings: onEditorSettings,
onImageUploadSuccessAction: onImageUploadSuccessAction,
onImageUploadFailureAction: onImageUploadFailureAction,
onEditorTextSizeChanged: onEditorTextSizeChanged,
width: width,
height: height,
);
Expand Down
Loading

0 comments on commit 194ccd3

Please sign in to comment.