From 15bd6f2342bbc8b988a627c86f6bcf9d773ca848 Mon Sep 17 00:00:00 2001 From: Xun Gong Date: Wed, 1 Sep 2021 13:09:20 -0700 Subject: [PATCH] Add "small" (extended) markdown style support --- lib/src/models/documents/attribute.dart | 8 ++++++++ lib/src/widgets/default_styles.dart | 4 ++++ lib/src/widgets/text_line.dart | 1 + lib/src/widgets/toolbar.dart | 9 +++++++++ 4 files changed, 22 insertions(+) diff --git a/lib/src/models/documents/attribute.dart b/lib/src/models/documents/attribute.dart index 97d82f15..467742d5 100644 --- a/lib/src/models/documents/attribute.dart +++ b/lib/src/models/documents/attribute.dart @@ -19,6 +19,7 @@ class Attribute { static final Map _registry = LinkedHashMap.of({ Attribute.bold.key: Attribute.bold, Attribute.italic.key: Attribute.italic, + Attribute.small.key: Attribute.small, Attribute.underline.key: Attribute.underline, Attribute.strikeThrough.key: Attribute.strikeThrough, Attribute.font.key: Attribute.font, @@ -43,6 +44,8 @@ class Attribute { static final ItalicAttribute italic = ItalicAttribute(); + static final SmallAttribute small = SmallAttribute(); + static final UnderlineAttribute underline = UnderlineAttribute(); static final StrikeThroughAttribute strikeThrough = StrikeThroughAttribute(); @@ -82,6 +85,7 @@ class Attribute { static final Set inlineKeys = { Attribute.bold.key, Attribute.italic.key, + Attribute.small.key, Attribute.underline.key, Attribute.strikeThrough.key, Attribute.link.key, @@ -217,6 +221,10 @@ class ItalicAttribute extends Attribute { ItalicAttribute() : super('italic', AttributeScope.INLINE, true); } +class SmallAttribute extends Attribute { + SmallAttribute() : super('small', AttributeScope.INLINE, true); +} + class UnderlineAttribute extends Attribute { UnderlineAttribute() : super('underline', AttributeScope.INLINE, true); } diff --git a/lib/src/widgets/default_styles.dart b/lib/src/widgets/default_styles.dart index 1cebe135..ca00cf19 100644 --- a/lib/src/widgets/default_styles.dart +++ b/lib/src/widgets/default_styles.dart @@ -51,6 +51,7 @@ class DefaultStyles { this.paragraph, this.bold, this.italic, + this.small, this.underline, this.strikeThrough, this.link, @@ -73,6 +74,7 @@ class DefaultStyles { final DefaultTextBlockStyle? paragraph; final TextStyle? bold; final TextStyle? italic; + final TextStyle? small; final TextStyle? underline; final TextStyle? strikeThrough; final TextStyle? sizeSmall; // 'small' @@ -147,6 +149,7 @@ class DefaultStyles { baseStyle, const Tuple2(0, 0), const Tuple2(0, 0), null), bold: const TextStyle(fontWeight: FontWeight.bold), italic: const TextStyle(fontStyle: FontStyle.italic), + small: const TextStyle(fontSize: 12), underline: const TextStyle(decoration: TextDecoration.underline), strikeThrough: const TextStyle(decoration: TextDecoration.lineThrough), link: TextStyle( @@ -205,6 +208,7 @@ class DefaultStyles { paragraph: other.paragraph ?? paragraph, bold: other.bold ?? bold, italic: other.italic ?? italic, + small: other.small ?? small, underline: other.underline ?? underline, strikeThrough: other.strikeThrough ?? strikeThrough, link: other.link ?? link, diff --git a/lib/src/widgets/text_line.dart b/lib/src/widgets/text_line.dart index 44715f6e..6da21a4c 100644 --- a/lib/src/widgets/text_line.dart +++ b/lib/src/widgets/text_line.dart @@ -181,6 +181,7 @@ class TextLine extends StatelessWidget { { Attribute.bold.key: defaultStyles.bold, Attribute.italic.key: defaultStyles.italic, + Attribute.small.key: defaultStyles.small, Attribute.link.key: defaultStyles.link, Attribute.underline.key: defaultStyles.underline, Attribute.strikeThrough.key: defaultStyles.strikeThrough, diff --git a/lib/src/widgets/toolbar.dart b/lib/src/widgets/toolbar.dart index dff2013c..2803948d 100644 --- a/lib/src/widgets/toolbar.dart +++ b/lib/src/widgets/toolbar.dart @@ -65,6 +65,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { double toolbarIconSize = kDefaultIconSize, bool showBoldButton = true, bool showItalicButton = true, + bool showSmallButton = false, bool showUnderLineButton = true, bool showStrikeThrough = true, bool showColorButton = true, @@ -96,6 +97,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { showHistory || showBoldButton || showItalicButton || + showSmallButton || showUnderLineButton || showStrikeThrough || showColorButton || @@ -142,6 +144,13 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { iconSize: toolbarIconSize, controller: controller, ), + if (showSmallButton) + ToggleStyleButton( + attribute: Attribute.small, + icon: Icons.format_size, + iconSize: toolbarIconSize, + controller: controller, + ), if (showUnderLineButton) ToggleStyleButton( attribute: Attribute.underline,