Add inline code formatting

pull/418/head
Xin Yao 4 years ago
parent 6f32b0eda8
commit 19600f7d8f
  1. 7
      lib/src/models/documents/attribute.dart
  2. 8
      lib/src/widgets/default_styles.dart
  3. 1
      lib/src/widgets/text_line.dart
  4. 9
      lib/src/widgets/toolbar.dart

@ -22,6 +22,7 @@ class Attribute<T> {
Attribute.small.key: Attribute.small, Attribute.small.key: Attribute.small,
Attribute.underline.key: Attribute.underline, Attribute.underline.key: Attribute.underline,
Attribute.strikeThrough.key: Attribute.strikeThrough, Attribute.strikeThrough.key: Attribute.strikeThrough,
Attribute.inlineCode.key: Attribute.inlineCode,
Attribute.font.key: Attribute.font, Attribute.font.key: Attribute.font,
Attribute.size.key: Attribute.size, Attribute.size.key: Attribute.size,
Attribute.link.key: Attribute.link, Attribute.link.key: Attribute.link,
@ -50,6 +51,8 @@ class Attribute<T> {
static final StrikeThroughAttribute strikeThrough = StrikeThroughAttribute(); static final StrikeThroughAttribute strikeThrough = StrikeThroughAttribute();
static final InlineCodeAttribute inlineCode = InlineCodeAttribute();
static final FontAttribute font = FontAttribute(null); static final FontAttribute font = FontAttribute(null);
static final SizeAttribute size = SizeAttribute(null); static final SizeAttribute size = SizeAttribute(null);
@ -240,6 +243,10 @@ class StrikeThroughAttribute extends Attribute<bool> {
StrikeThroughAttribute() : super('strike', AttributeScope.INLINE, true); StrikeThroughAttribute() : super('strike', AttributeScope.INLINE, true);
} }
class InlineCodeAttribute extends Attribute<bool> {
InlineCodeAttribute() : super('code', AttributeScope.INLINE, true);
}
class FontAttribute extends Attribute<String?> { class FontAttribute extends Attribute<String?> {
FontAttribute(String? val) : super('font', AttributeScope.INLINE, val); FontAttribute(String? val) : super('font', AttributeScope.INLINE, val);
} }

@ -54,6 +54,7 @@ class DefaultStyles {
this.small, this.small,
this.underline, this.underline,
this.strikeThrough, this.strikeThrough,
this.inlineCode,
this.link, this.link,
this.color, this.color,
this.placeHolder, this.placeHolder,
@ -77,6 +78,7 @@ class DefaultStyles {
final TextStyle? small; final TextStyle? small;
final TextStyle? underline; final TextStyle? underline;
final TextStyle? strikeThrough; final TextStyle? strikeThrough;
final TextStyle? inlineCode;
final TextStyle? sizeSmall; // 'small' final TextStyle? sizeSmall; // 'small'
final TextStyle? sizeLarge; // 'large' final TextStyle? sizeLarge; // 'large'
final TextStyle? sizeHuge; // 'huge' final TextStyle? sizeHuge; // 'huge'
@ -152,6 +154,11 @@ class DefaultStyles {
small: const TextStyle(fontSize: 12, color: Colors.black45), small: const TextStyle(fontSize: 12, color: Colors.black45),
underline: const TextStyle(decoration: TextDecoration.underline), underline: const TextStyle(decoration: TextDecoration.underline),
strikeThrough: const TextStyle(decoration: TextDecoration.lineThrough), strikeThrough: const TextStyle(decoration: TextDecoration.lineThrough),
inlineCode: TextStyle(
color: Colors.blue.shade900.withOpacity(0.9),
fontFamily: fontFamily,
fontSize: 13,
),
link: TextStyle( link: TextStyle(
color: themeData.colorScheme.secondary, color: themeData.colorScheme.secondary,
decoration: TextDecoration.underline, decoration: TextDecoration.underline,
@ -211,6 +218,7 @@ class DefaultStyles {
small: other.small ?? small, small: other.small ?? small,
underline: other.underline ?? underline, underline: other.underline ?? underline,
strikeThrough: other.strikeThrough ?? strikeThrough, strikeThrough: other.strikeThrough ?? strikeThrough,
inlineCode: other.inlineCode ?? inlineCode,
link: other.link ?? link, link: other.link ?? link,
color: other.color ?? color, color: other.color ?? color,
placeHolder: other.placeHolder ?? placeHolder, placeHolder: other.placeHolder ?? placeHolder,

@ -192,6 +192,7 @@ class TextLine extends StatelessWidget {
Attribute.link.key: defaultStyles.link, Attribute.link.key: defaultStyles.link,
Attribute.underline.key: defaultStyles.underline, Attribute.underline.key: defaultStyles.underline,
Attribute.strikeThrough.key: defaultStyles.strikeThrough, Attribute.strikeThrough.key: defaultStyles.strikeThrough,
Attribute.inlineCode.key: defaultStyles.inlineCode,
}.forEach((k, s) { }.forEach((k, s) {
if (style.values.any((v) => v.key == k)) { if (style.values.any((v) => v.key == k)) {
if (k == Attribute.underline.key || k == Attribute.strikeThrough.key) { if (k == Attribute.underline.key || k == Attribute.strikeThrough.key) {

@ -70,6 +70,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
bool showSmallButton = false, bool showSmallButton = false,
bool showUnderLineButton = true, bool showUnderLineButton = true,
bool showStrikeThrough = true, bool showStrikeThrough = true,
bool showInlineCode = true,
bool showColorButton = true, bool showColorButton = true,
bool showBackgroundColorButton = true, bool showBackgroundColorButton = true,
bool showClearFormat = true, bool showClearFormat = true,
@ -103,6 +104,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
showSmallButton || showSmallButton ||
showUnderLineButton || showUnderLineButton ||
showStrikeThrough || showStrikeThrough ||
showInlineCode ||
showColorButton || showColorButton ||
showBackgroundColorButton || showBackgroundColorButton ||
showClearFormat || showClearFormat ||
@ -169,6 +171,13 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
), ),
if (showInlineCode)
ToggleStyleButton(
attribute: Attribute.inlineCode,
icon: Icons.code,
iconSize: toolbarIconSize,
controller: controller,
),
if (showColorButton) if (showColorButton)
ColorButton( ColorButton(
icon: Icons.color_lens, icon: Icons.color_lens,

Loading…
Cancel
Save