Skip to content

Commit

Permalink
Fix focus indicator still display, but can not fill text in composer …
Browse files Browse the repository at this point in the history
…body after change `color background`, `font name`
  • Loading branch information
dab246 committed Oct 22, 2024
1 parent 49f5484 commit 940b94d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class RichTextWebController extends BaseRichTextController {

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

final editorController = HtmlEditorController();

Expand Down Expand Up @@ -151,8 +152,8 @@ class RichTextWebController extends BaseRichTextController {
openMenuSelectColor(
context,
selectedTextBackgroundColor.value,
onResetToDefault: () => applyBackgroundColor(Colors.white),
onSelectColor: applyBackgroundColor
onResetToDefault: () => _applyBackgroundColor(Colors.white),
onSelectColor: _applyBackgroundColor
);
break;
default:
Expand All @@ -162,24 +163,26 @@ class RichTextWebController extends BaseRichTextController {
}
}

void _applyForegroundColor(Color? selectedColor) {
Future<void> _applyForegroundColor(Color? selectedColor) async {
final newColor = selectedColor ?? Colors.black;
final colorAsString = newColor.toHexTriplet();
log('RichTextWebController::_applyForegroundColor():colorAsString: $colorAsString');
selectedTextColor.value = newColor;
editorController.execSummernoteAPI(
RichTextStyleType.textColor.summernoteNameAPI,
value: colorAsString);
await _requestEditorFocus();
}

void applyBackgroundColor(Color? selectedColor) {
Future<void> _applyBackgroundColor(Color? selectedColor) async {
final newColor = selectedColor ?? Colors.white;
final colorAsString = newColor.toHexTriplet();
log('RichTextWebController::_applyBackgroundColor():colorAsString: $colorAsString');
selectedTextBackgroundColor.value = newColor;
editorController.execSummernoteAPI(
RichTextStyleType.textBackgroundColor.summernoteNameAPI,
value: colorAsString);
await _requestEditorFocus();
}

void _selectTextStyleType(RichTextStyleType textStyleType) {
Expand All @@ -197,17 +200,19 @@ class RichTextWebController extends BaseRichTextController {
editorController.insertHtml("<div>${inlineImage.base64Uri ?? ''}</div><br>");
}

void applyNewFontStyle(FontNameType? newFont) {
Future<void> applyNewFontStyle(FontNameType? newFont) async {
final fontSelected = newFont ?? FontNameType.sansSerif;
selectedFontName.value = fontSelected;
editorController.execSummernoteAPI(
RichTextStyleType.fontName.summernoteNameAPI,
value: fontSelected.value);
await _requestEditorFocus();
}

void applyNewFontSize(int? newSize) {
Future<void> applyNewFontSize(int? newSize) async {
selectedFontSize.value = newSize ?? fontSizeDefault;
editorController.setFontSize(newSize ?? fontSizeDefault);
await _requestEditorFocus();
}

bool get isMenuFontOpen => menuFontStatus.value == DropdownMenuFontStatus.open;
Expand Down Expand Up @@ -240,22 +245,23 @@ class RichTextWebController extends BaseRichTextController {
editorController.toggleCodeView();
}

void applyHeaderStyle(HeaderStyleType? newStyle) {
Future<void> applyHeaderStyle(HeaderStyleType? newStyle) async {
final styleSelected = newStyle ?? HeaderStyleType.normal;
if (styleSelected == HeaderStyleType.blockquote || styleSelected == HeaderStyleType.code) {
editorController.execCommand(
RichTextStyleType.headerStyle.commandAction,
argument: styleSelected.styleValue);
editorController.setFocus();
} else {
editorController.execSummernoteAPI(styleSelected.summernoteNameAPI);
}
await _requestEditorFocus();
}

void applyParagraphType(ParagraphType newParagraph) {
Future<void> applyParagraphType(ParagraphType newParagraph) async {
selectedParagraph.value = newParagraph;
editorController.execSummernoteAPI(newParagraph.summernoteNameAPI);
menuParagraphController.hideMenu();
await _requestEditorFocus();
}

void closeAllMenuPopup() {
Expand All @@ -273,10 +279,11 @@ class RichTextWebController extends BaseRichTextController {
}
}

void applyOrderListType(OrderListType newOrderList) {
Future<void> applyOrderListType(OrderListType newOrderList) async {
selectedOrderList.value = newOrderList;
editorController.execSummernoteAPI(newOrderList.summernoteNameAPI);
menuOrderListController.hideMenu();
await _requestEditorFocus();
}

void insertImageAsBase64({required PlatformFile platformFile, int? maxWidth}) {
Expand All @@ -297,14 +304,19 @@ class RichTextWebController extends BaseRichTextController {

formattingOptionsState.value = newState;

if (isFormattingOptionsEnabled) {
FocusManager.instance.primaryFocus?.unfocus();
editorController.setFocus();
}
FocusManager.instance.primaryFocus?.unfocus();
editorController.setFocus();
}

bool get isFormattingOptionsEnabled => formattingOptionsState.value == FormattingOptionsState.enabled;

Future<void> _requestEditorFocus() async {
await Future.delayed(
const Duration(milliseconds: _applyStyleDelayTimeMilliseconds)
);
editorController.setFocus();
}

@override
void onClose() {
menuParagraphController.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ mixin RichTextButtonMixin {
: DropdownMenuFontStatus.closed;
richTextController.menuHeaderStyleStatus.value = newStatus;
},
onChanged: (newStyle) => richTextController.applyHeaderStyle(newStyle)),
onChanged: richTextController.applyHeaderStyle),
Container(
width: 130,
padding: const EdgeInsets.only(left: 4.0, right: 4.0),
child: DropDownButtonWidget<FontNameType>(
items: FontNameType.values,
itemSelected: richTextController.selectedFontName.value,
onChanged: (newFont) => richTextController.applyNewFontStyle(newFont),
onChanged: richTextController.applyNewFontStyle,
onMenuStateChange: (isOpen) {
final newStatus = isOpen
? DropdownMenuFontStatus.open
Expand Down Expand Up @@ -325,7 +325,7 @@ mixin RichTextButtonMixin {
.map((paragraph) => paragraph.buildButtonWidget(
context,
_imagePaths,
(paragraph) => richTextController.applyParagraphType(paragraph)))
richTextController.applyParagraphType))
.toList(),
iconButton: buildWrapIconStyleText(
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 5),
Expand All @@ -346,7 +346,7 @@ mixin RichTextButtonMixin {
.map((orderType) => orderType.buildButtonWidget(
context,
_imagePaths,
(orderType) => richTextController.applyOrderListType(orderType)))
richTextController.applyOrderListType))
.toList(),
iconButton: buildWrapIconStyleText(
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 5),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ToolbarRichTextWebBuilder extends StatelessWidget with RichTextButtonMixin
child: DropDownButtonWidget<FontNameType>(
items: FontNameType.values,
itemSelected: richTextWebController.selectedFontName.value,
onChanged: (newFont) => richTextWebController.applyNewFontStyle(newFont),
onChanged: richTextWebController.applyNewFontStyle,
onMenuStateChange: (isOpen) {
final newStatus = isOpen
? DropdownMenuFontStatus.open
Expand Down Expand Up @@ -211,7 +211,7 @@ class ToolbarRichTextWebBuilder extends StatelessWidget with RichTextButtonMixin
.map((paragraph) => paragraph.buildButtonWidget(
context,
_imagePaths,
(paragraph) => richTextWebController.applyParagraphType(paragraph)))
richTextWebController.applyParagraphType))
.toList(),
iconButton: buildWrapIconStyleText(
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 5),
Expand All @@ -235,7 +235,7 @@ class ToolbarRichTextWebBuilder extends StatelessWidget with RichTextButtonMixin
.map((orderType) => orderType.buildButtonWidget(
context,
_imagePaths,
(orderType) => richTextWebController.applyOrderListType(orderType)))
richTextWebController.applyOrderListType))
.toList(),
iconButton: buildWrapIconStyleText(
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 5),
Expand Down
1 change: 1 addition & 0 deletions lib/features/contact/presentation/contact_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/utils/platform_info.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:core/presentation/extensions/color_extension.dart';
import 'package:core/presentation/utils/responsive_utils.dart';
import 'package:core/presentation/views/button/icon_button_web.dart';
import 'package:core/presentation/views/checkbox/labeled_checkbox.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/email_recovery/presentation/widgets/check_box_has_attachment_widget.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/advanced_filter_controller.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/input_field_focus_manager.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
Expand Down Expand Up @@ -113,25 +113,12 @@ class AdvancedSearchFilterFormBottomView extends GetWidget<AdvancedFilterControl
FocusNode? nextFocusNode,
}
) {
return Obx(
() => KeyboardListener(
focusNode: FocusNode(),
onKeyEvent: (event) {
if (event is KeyDownEvent &&
event.logicalKey == LogicalKeyboardKey.tab) {
nextFocusNode?.requestFocus();
}
},
child: LabeledCheckbox(
label: AppLocalizations.of(context).hasAttachment,
focusNode: currentFocusNode,
contentPadding: EdgeInsets.zero,
value: controller.hasAttachment.value,
activeColor: AppColor.primaryColor,
onChanged: controller.onHasAttachmentCheckboxChanged,
),
),
);
return Obx(() => CheckBoxHasAttachmentWidget(
currentFocusNode: currentFocusNode,
nextFocusNode: nextFocusNode,
onChanged: controller.onHasAttachmentCheckboxChanged,
hasAttachmentValue: controller.hasAttachment.value,
));
}

Widget _buildButton({
Expand Down

0 comments on commit 940b94d

Please sign in to comment.