diff --git a/lib/src/models/documents/attribute.dart b/lib/src/models/documents/attribute.dart index f52f70b7..db667ce1 100644 --- a/lib/src/models/documents/attribute.dart +++ b/lib/src/models/documents/attribute.dart @@ -22,6 +22,7 @@ class Attribute { Attribute.small.key: Attribute.small, Attribute.underline.key: Attribute.underline, Attribute.strikeThrough.key: Attribute.strikeThrough, + Attribute.inlineCode.key: Attribute.inlineCode, Attribute.font.key: Attribute.font, Attribute.size.key: Attribute.size, Attribute.link.key: Attribute.link, @@ -50,6 +51,8 @@ class Attribute { static final StrikeThroughAttribute strikeThrough = StrikeThroughAttribute(); + static final InlineCodeAttribute inlineCode = InlineCodeAttribute(); + static final FontAttribute font = FontAttribute(null); static final SizeAttribute size = SizeAttribute(null); @@ -240,6 +243,10 @@ class StrikeThroughAttribute extends Attribute { StrikeThroughAttribute() : super('strike', AttributeScope.INLINE, true); } +class InlineCodeAttribute extends Attribute { + InlineCodeAttribute() : super('code', AttributeScope.INLINE, true); +} + class FontAttribute extends Attribute { FontAttribute(String? val) : super('font', AttributeScope.INLINE, val); } diff --git a/lib/src/widgets/default_styles.dart b/lib/src/widgets/default_styles.dart index 4c84966e..ea583909 100644 --- a/lib/src/widgets/default_styles.dart +++ b/lib/src/widgets/default_styles.dart @@ -54,6 +54,7 @@ class DefaultStyles { this.small, this.underline, this.strikeThrough, + this.inlineCode, this.link, this.color, this.placeHolder, @@ -77,6 +78,7 @@ class DefaultStyles { final TextStyle? small; final TextStyle? underline; final TextStyle? strikeThrough; + final TextStyle? inlineCode; final TextStyle? sizeSmall; // 'small' final TextStyle? sizeLarge; // 'large' final TextStyle? sizeHuge; // 'huge' @@ -152,6 +154,11 @@ class DefaultStyles { small: const TextStyle(fontSize: 12, color: Colors.black45), underline: const TextStyle(decoration: TextDecoration.underline), strikeThrough: const TextStyle(decoration: TextDecoration.lineThrough), + inlineCode: TextStyle( + color: Colors.blue.shade900.withOpacity(0.9), + fontFamily: fontFamily, + fontSize: 13, + ), link: TextStyle( color: themeData.colorScheme.secondary, decoration: TextDecoration.underline, @@ -211,6 +218,7 @@ class DefaultStyles { small: other.small ?? small, underline: other.underline ?? underline, strikeThrough: other.strikeThrough ?? strikeThrough, + inlineCode: other.inlineCode ?? inlineCode, link: other.link ?? link, color: other.color ?? color, placeHolder: other.placeHolder ?? placeHolder, diff --git a/lib/src/widgets/text_line.dart b/lib/src/widgets/text_line.dart index f8a3f396..f87645ab 100644 --- a/lib/src/widgets/text_line.dart +++ b/lib/src/widgets/text_line.dart @@ -192,6 +192,7 @@ class TextLine extends StatelessWidget { Attribute.link.key: defaultStyles.link, Attribute.underline.key: defaultStyles.underline, Attribute.strikeThrough.key: defaultStyles.strikeThrough, + Attribute.inlineCode.key: defaultStyles.inlineCode, }.forEach((k, s) { if (style.values.any((v) => v.key == k)) { if (k == Attribute.underline.key || k == Attribute.strikeThrough.key) { diff --git a/lib/src/widgets/toolbar.dart b/lib/src/widgets/toolbar.dart index 80e04e01..1fd6b0f1 100644 --- a/lib/src/widgets/toolbar.dart +++ b/lib/src/widgets/toolbar.dart @@ -70,6 +70,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { bool showSmallButton = false, bool showUnderLineButton = true, bool showStrikeThrough = true, + bool showInlineCode = true, bool showColorButton = true, bool showBackgroundColorButton = true, bool showClearFormat = true, @@ -103,6 +104,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { showSmallButton || showUnderLineButton || showStrikeThrough || + showInlineCode || showColorButton || showBackgroundColorButton || showClearFormat || @@ -169,6 +171,13 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { iconSize: toolbarIconSize, controller: controller, ), + if (showInlineCode) + ToggleStyleButton( + attribute: Attribute.inlineCode, + icon: Icons.code, + iconSize: toolbarIconSize, + controller: controller, + ), if (showColorButton) ColorButton( icon: Icons.color_lens,