From 717ecc2aaa1149a000ce940d59d2b8faf3aa630a Mon Sep 17 00:00:00 2001 From: Ellet Date: Wed, 13 Dec 2023 14:29:23 +0300 Subject: [PATCH] Fix bug #1562 --- CHANGELOG.md | 2 +- .../presentation/quill/my_quill_editor.dart | 16 ++++++++++ .../lib/presentation/quill/quill_screen.dart | 14 --------- .../editor/elements/list/ordered_list.dart | 8 +++-- .../editor/elements/list/unordered_list.dart | 8 +++-- lib/src/widgets/quill/text_block.dart | 30 +++++++++++++++++-- 6 files changed, 56 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b6943aea..0d849055e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file. * Add the new translations for ru, uk arb files by [#1575](https://github.com/singerdmx/flutter-quill/pull/1575) * 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) ## 9.0.2-dev.1 * Add configurations for the new dropdown `QuillToolbarSelectHeaderStyleButton`, you can use the orignal one or this diff --git a/example/lib/presentation/quill/my_quill_editor.dart b/example/lib/presentation/quill/my_quill_editor.dart index 390f08577..75277f1e9 100644 --- a/example/lib/presentation/quill/my_quill_editor.dart +++ b/example/lib/presentation/quill/my_quill_editor.dart @@ -33,6 +33,22 @@ class MyQuillEditor extends StatelessWidget { scrollController: scrollController, focusNode: focusNode, configurations: configurations.copyWith( + elementOptions: const QuillEditorElementOptions( + codeBlock: QuillEditorCodeBlockElementOptions( + enableLineNumbers: true, + ), + // orderedList: QuillEditorOrderedListElementOptions( + // backgroundColor: Colors.amber, + // fontColor: Colors.black, + // ), + // unorderedList: QuillEditorUnOrderedListElementOptions( + // backgroundColor: Colors.green, + // fontColor: Colors.red, + // ), + unorderedList: QuillEditorUnOrderedListElementOptions( + useTextColorForDot: false, + ), + ), customStyles: const DefaultStyles( h1: DefaultTextBlockStyle( TextStyle( diff --git a/example/lib/presentation/quill/quill_screen.dart b/example/lib/presentation/quill/quill_screen.dart index 3ed06a74d..991dd6331 100644 --- a/example/lib/presentation/quill/quill_screen.dart +++ b/example/lib/presentation/quill/quill_screen.dart @@ -126,20 +126,6 @@ class _QuillScreenState extends State { sharedConfigurations: _sharedConfigurations, controller: _controller, readOnly: _isReadOnly, - customStyles: const DefaultStyles(), - elementOptions: const QuillEditorElementOptions( - codeBlock: QuillEditorCodeBlockElementOptions( - enableLineNumbers: true, - ), - // orderedList: QuillEditorOrderedListElementOptions( - // backgroundColor: Colors.amber, - // fontColor: Colors.black, - // ), - // unorderedList: QuillEditorUnOrderedListElementOptions( - // backgroundColor: Colors.green, - // fontColor: Colors.red, - // ), - ), ), scrollController: _editorScrollController, focusNode: _editorFocusNode, diff --git a/lib/src/models/config/editor/elements/list/ordered_list.dart b/lib/src/models/config/editor/elements/list/ordered_list.dart index b48252991..5d7f7acaa 100644 --- a/lib/src/models/config/editor/elements/list/ordered_list.dart +++ b/lib/src/models/config/editor/elements/list/ordered_list.dart @@ -4,11 +4,15 @@ import 'package:flutter/widgets.dart' show Color; @immutable class QuillEditorOrderedListElementOptions extends Equatable { - const QuillEditorOrderedListElementOptions( - {this.backgroundColor, this.fontColor}); + const QuillEditorOrderedListElementOptions({ + this.backgroundColor, + this.fontColor, + this.useTextColorForDot = true, + }); final Color? backgroundColor; final Color? fontColor; + final bool useTextColorForDot; @override List get props => []; } diff --git a/lib/src/models/config/editor/elements/list/unordered_list.dart b/lib/src/models/config/editor/elements/list/unordered_list.dart index 3fe570eb2..23333ef30 100644 --- a/lib/src/models/config/editor/elements/list/unordered_list.dart +++ b/lib/src/models/config/editor/elements/list/unordered_list.dart @@ -4,11 +4,15 @@ import 'package:flutter/widgets.dart' show Color; @immutable class QuillEditorUnOrderedListElementOptions extends Equatable { - const QuillEditorUnOrderedListElementOptions( - {this.backgroundColor, this.fontColor}); + const QuillEditorUnOrderedListElementOptions({ + this.backgroundColor, + this.fontColor, + this.useTextColorForDot = true, + }); final Color? backgroundColor; final Color? fontColor; + final bool useTextColorForDot; @override List get props => []; } diff --git a/lib/src/widgets/quill/text_block.dart b/lib/src/widgets/quill/text_block.dart index 3d1bfca32..5496f3979 100644 --- a/lib/src/widgets/quill/text_block.dart +++ b/lib/src/widgets/quill/text_block.dart @@ -17,6 +17,7 @@ import '../others/text_selection.dart'; import '../style_widgets/bullet_point.dart'; import '../style_widgets/checkbox_point.dart'; import '../style_widgets/number_point.dart'; +import '../toolbar/base_toolbar.dart'; import 'quill_controller.dart'; import 'text_line.dart'; @@ -211,12 +212,29 @@ class EditableTextBlock extends StatelessWidget { final fontSize = defaultStyles.paragraph?.style.fontSize ?? 16; final attrs = line.style.attributes; + final fontColor = + line.toDelta().operations.first.attributes?[Attribute.color.key] != null + ? hexToColor( + line + .toDelta() + .operations + .first + .attributes?[Attribute.color.key], + ) + : null; + if (attrs[Attribute.list.key] == Attribute.ol) { return QuillEditorNumberPoint( index: index, indentLevelCounts: indentLevelCounts, count: count, - style: defaultStyles.leading!.style, + style: defaultStyles.leading!.style.copyWith( + color: context.quillEditorElementOptions?.orderedList + .useTextColorForDot == + true + ? fontColor + : null, + ), attrs: attrs, width: _numberPointWidth(fontSize, count), padding: fontSize / 2, @@ -225,8 +243,14 @@ class EditableTextBlock extends StatelessWidget { if (attrs[Attribute.list.key] == Attribute.ul) { return QuillEditorBulletPoint( - style: - defaultStyles.leading!.style.copyWith(fontWeight: FontWeight.bold), + style: defaultStyles.leading!.style.copyWith( + fontWeight: FontWeight.bold, + color: context.quillEditorElementOptions?.unorderedList + .useTextColorForDot == + true + ? fontColor + : null, + ), width: fontSize * 2, padding: fontSize / 2, );