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.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<T> {
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<bool> {
StrikeThroughAttribute() : super('strike', AttributeScope.INLINE, true);
}
class InlineCodeAttribute extends Attribute<bool> {
InlineCodeAttribute() : super('code', AttributeScope.INLINE, true);
}
class FontAttribute extends Attribute<String?> {
FontAttribute(String? val) : super('font', AttributeScope.INLINE, val);
}

@ -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,

@ -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) {

@ -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,

Loading…
Cancel
Save