Add "small" (extended) markdown style support

pull/382/head
Xun Gong 4 years ago
parent 7c7f61fe90
commit 15bd6f2342
  1. 8
      lib/src/models/documents/attribute.dart
  2. 4
      lib/src/widgets/default_styles.dart
  3. 1
      lib/src/widgets/text_line.dart
  4. 9
      lib/src/widgets/toolbar.dart

@ -19,6 +19,7 @@ class Attribute<T> {
static final Map<String, Attribute> _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<T> {
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<T> {
static final Set<String> 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<bool> {
ItalicAttribute() : super('italic', AttributeScope.INLINE, true);
}
class SmallAttribute extends Attribute<bool> {
SmallAttribute() : super('small', AttributeScope.INLINE, true);
}
class UnderlineAttribute extends Attribute<bool> {
UnderlineAttribute() : super('underline', AttributeScope.INLINE, true);
}

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

@ -181,6 +181,7 @@ class TextLine extends StatelessWidget {
<String, TextStyle?>{
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,

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

Loading…
Cancel
Save