TF-1878 Fix font family not changed correctly in composer

(cherry picked from commit a4c72a79abf429aa2938c8218308f1ac16f89d76)
This commit is contained in:
dab246
2023-06-16 12:45:26 +07:00
committed by Dat H. Pham
parent f589b11637
commit 68145165be
3 changed files with 73 additions and 14 deletions
@@ -174,7 +174,7 @@ class DropDownButtonWidget<T> extends StatelessWidget {
return item.name ?? '';
}
if (item is FontNameType) {
return item.fontFamily;
return item.title;
}
if (item is rich_text_composer.SafeFont) {
return item.name;
@@ -47,8 +47,16 @@ class RichTextWebController extends BaseRichTextController {
});
}
void onEditorSettingsChange(EditorSettings settings) async {
log('RichTextWebController::onEditorSettingsChange():foregroundColor: ${settings.foregroundColor} | backgroundColor: ${settings.backgroundColor}');
void onEditorSettingsChange(EditorSettings settings) {
_updateTextStyle(settings);
_updateFontName(settings);
_updateTextColor(settings);
_updateBackgroundTextColor(settings);
_updateOrderList(settings);
_updateParagraph(settings);
}
void _updateTextStyle(EditorSettings settings) {
listTextStyleApply.clear();
if (settings.isBold) {
@@ -67,11 +75,35 @@ class RichTextWebController extends BaseRichTextController {
listTextStyleApply.add(RichTextStyleType.strikeThrough);
}
log('RichTextWebController::onEditorSettingsChange(): $listTextStyleApply');
log('RichTextWebController::_updateTextStyle(): $listTextStyleApply');
}
void _updateFontName(EditorSettings settings) {
log('RichTextWebController::_updateFontName():fontName: ${settings.fontName}');
final matchedFontName = FontNameType.values.firstWhereOrNull((fontName) => fontName.value == settings.fontName);
log('RichTextWebController::_updateFontName():matchedFontName: $matchedFontName');
if (matchedFontName != null) {
selectedFontName.value = matchedFontName;
}
}
void _updateTextColor(EditorSettings settings) {
selectedTextColor.value = settings.foregroundColor;
selectedTextBackgroundColor.value = settings.backgroundColor;
}
void _updateBackgroundTextColor(EditorSettings settings) {
selectedTextBackgroundColor.value = settings.backgroundColor;
}
void _updateOrderList(EditorSettings settings) {
if (settings.isOl) {
selectedOrderList.value = OrderListType.numberedList;
} else if (settings.isUl) {
selectedOrderList.value = OrderListType.bulletedList;
}
}
void _updateParagraph(EditorSettings settings) {
if (settings.isAlignCenter) {
selectedParagraph.value = ParagraphType.alignCenter;
} else if (settings.isAlignJustify) {
@@ -81,12 +113,6 @@ class RichTextWebController extends BaseRichTextController {
} else if (settings.isAlignRight) {
selectedParagraph.value = ParagraphType.alignRight;
}
if (settings.isOl) {
selectedOrderList.value = OrderListType.numberedList;
} else if (settings.isUl) {
selectedOrderList.value = OrderListType.bulletedList;
}
}
void applyRichTextStyle(BuildContext context, RichTextStyleType textStyleType) {
@@ -157,8 +183,8 @@ class RichTextWebController extends BaseRichTextController {
final fontSelected = newFont ?? FontNameType.sansSerif;
selectedFontName.value = fontSelected;
editorController.execCommand(
RichTextStyleType.fontName.commandAction,
argument: fontSelected.fontFamily);
RichTextStyleType.fontName.commandAction,
argument: fontSelected.value);
editorController.setFocus();
}
@@ -15,7 +15,7 @@ enum FontNameType {
sansSerif,
verdana;
String get fontFamily {
String get title {
switch(this) {
case FontNameType.arial:
return 'Arial';
@@ -47,4 +47,37 @@ enum FontNameType {
return 'Verdana';
}
}
String get value {
switch(this) {
case FontNameType.arial:
return 'Arial';
case FontNameType.arialBlack:
return 'Arial Black';
case FontNameType.brushScriptMT:
return 'Brush Script MT';
case FontNameType.comicSansMS:
return 'Comic Sans MS';
case FontNameType.courierNew:
return 'Courier New';
case FontNameType.helveticaNeue:
return 'Helvetica Neue';
case FontNameType.helvetica:
return 'Helvetica';
case FontNameType.impact:
return 'Impact';
case FontNameType.lucidaGrande:
return 'Lucida Grande';
case FontNameType.tahoma:
return 'Tahoma';
case FontNameType.timesNewRoman:
return 'Times New Roman';
case FontNameType.trebuchetMS:
return 'Trebuchet MS';
case FontNameType.sansSerif:
return 'sans-serif';
case FontNameType.verdana:
return 'Verdana';
}
}
}