diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d849055e..ac3976f72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. * Add a new dropdown button by [#1575](https://github.com/singerdmx/flutter-quill/pull/1575) * Update the default style values by [#1575](https://github.com/singerdmx/flutter-quill/pull/1575) * Fix bug [#1562](https://github.com/singerdmx/flutter-quill/issues/1562) +* Fix the second bug of [#1480](https://github.com/singerdmx/flutter-quill/issues/1480) ## 9.0.2-dev.1 * Add configurations for the new dropdown `QuillToolbarSelectHeaderStyleButton`, you can use the orignal one or this diff --git a/lib/src/utils/font.dart b/lib/src/utils/font.dart index 5d1aa018e..423c95819 100644 --- a/lib/src/utils/font.dart +++ b/lib/src/utils/font.dart @@ -1,3 +1,5 @@ +import '../../flutter_quill.dart'; + dynamic getFontSize(dynamic sizeValue) { if (sizeValue is String && ['small', 'normal', 'large', 'huge'].contains(sizeValue)) { @@ -19,3 +21,32 @@ dynamic getFontSize(dynamic sizeValue) { } return fontSize; } + +double? getFontSizeAsDouble(dynamic sizeValue, + {required DefaultStyles defaultStyles}) { + if (sizeValue is String && + ['small', 'normal', 'large', 'huge'].contains(sizeValue)) { + return switch (sizeValue) { + 'small' => defaultStyles.sizeSmall?.fontSize, + 'normal' => null, + 'large' => defaultStyles.sizeLarge?.fontSize, + 'huge' => defaultStyles.sizeHuge?.fontSize, + String() => throw ArgumentError(), + }; + } + + if (sizeValue is double) { + return sizeValue; + } + + if (sizeValue is int) { + return sizeValue.toDouble(); + } + + assert(sizeValue is String); + final fontSize = double.tryParse(sizeValue); + if (fontSize == null) { + throw ArgumentError('Invalid size $sizeValue'); + } + return fontSize; +} diff --git a/lib/src/widgets/quill/text_block.dart b/lib/src/widgets/quill/text_block.dart index 86fb029f7..240ce83ad 100644 --- a/lib/src/widgets/quill/text_block.dart +++ b/lib/src/widgets/quill/text_block.dart @@ -7,6 +7,7 @@ import '../../models/documents/nodes/block.dart'; import '../../models/documents/nodes/line.dart'; import '../../models/structs/vertical_spacing.dart'; import '../../utils/delta.dart'; +import '../../utils/font.dart'; import '../../utils/string.dart'; import '../editor/editor.dart'; import '../others/box.dart'; @@ -213,6 +214,7 @@ class EditableTextBlock extends StatelessWidget { final fontSize = defaultStyles.paragraph?.style.fontSize ?? 16; final attrs = line.style.attributes; + // Of the color button final fontColor = line.toDelta().operations.first.attributes?[Attribute.color.key] != null ? hexToColor( @@ -223,17 +225,28 @@ class EditableTextBlock extends StatelessWidget { .attributes?[Attribute.color.key], ) : null; - // final textAlign = line.style.attributes['align']?.value != null - // ? getTextAlign(line.style.attributes['align']?.value) + + // Of the size button + final size = + line.toDelta().operations.first.attributes?[Attribute.size.key] != null + ? getFontSizeAsDouble( + line.toDelta().operations.first.attributes?[Attribute.size.key], + defaultStyles: defaultStyles, + ) + : null; + + // Of the alignment buttons + // final textAlign = line.style.attributes[Attribute.align.key]?.value != null + // ? getTextAlign(line.style.attributes[Attribute.align.key]?.value) // : null; if (attrs[Attribute.list.key] == Attribute.ol) { return QuillEditorNumberPoint( index: index, - // textAlign: textAlign, indentLevelCounts: indentLevelCounts, count: count, style: defaultStyles.leading!.style.copyWith( + fontSize: size, color: context.quillEditorElementOptions?.orderedList .useTextColorForDot == true @@ -250,6 +263,7 @@ class EditableTextBlock extends StatelessWidget { return QuillEditorBulletPoint( style: defaultStyles.leading!.style.copyWith( fontWeight: FontWeight.bold, + fontSize: size, color: context.quillEditorElementOptions?.unorderedList .useTextColorForDot == true @@ -258,7 +272,6 @@ class EditableTextBlock extends StatelessWidget { ), width: fontSize * 2, padding: fontSize / 2, - // textAlign: textAlign, ); } @@ -284,7 +297,6 @@ class EditableTextBlock extends StatelessWidget { attrs: attrs, padding: fontSize, withDot: false, - // textAlign: textAlign, ); } return null; diff --git a/lib/src/widgets/quill/text_line.dart b/lib/src/widgets/quill/text_line.dart index eee839d53..0889d8aa6 100644 --- a/lib/src/widgets/quill/text_line.dart +++ b/lib/src/widgets/quill/text_line.dart @@ -404,7 +404,11 @@ class _TextLineState extends State { res = res.merge(defaultStyles.sizeHuge); break; default: - res = res.merge(TextStyle(fontSize: getFontSize(size.value))); + res = res.merge(TextStyle( + fontSize: getFontSize( + size.value, + ), + )); } } diff --git a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart b/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart index c8c375614..cb46bab78 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state_text_input_client_mixin.dart @@ -224,7 +224,8 @@ mixin RawEditorStateTextInputClientMixin on EditorState widget.configurations.controller.selectedFontSize == '0' ? null : getFontSize( - widget.configurations.controller.selectedFontSize), + widget.configurations.controller.selectedFontSize, + ), ), ); }