From 99ec1a7b04a98473db7baf7d46ca51b67934022f Mon Sep 17 00:00:00 2001 From: CatHood0 Date: Thu, 4 Jul 2024 16:48:56 -0400 Subject: [PATCH] chore: dart fixes --- ..._style_dropdown_button_configurations.dart | 13 ++-- .../simple_toolbar_button_options.dart | 2 +- lib/src/models/documents/attribute.dart | 61 +++++++++++++------ lib/src/widgets/others/default_styles.dart | 18 +++--- lib/src/widgets/quill/text_line.dart | 5 +- .../select_line_height_dropdown_button.dart | 31 +++++++--- lib/src/widgets/toolbar/simple_toolbar.dart | 13 ++-- 7 files changed, 89 insertions(+), 54 deletions(-) diff --git a/lib/src/models/config/toolbar/buttons/select_line_height_style_dropdown_button_configurations.dart b/lib/src/models/config/toolbar/buttons/select_line_height_style_dropdown_button_configurations.dart index feb9794b..c8d3a3bd 100644 --- a/lib/src/models/config/toolbar/buttons/select_line_height_style_dropdown_button_configurations.dart +++ b/lib/src/models/config/toolbar/buttons/select_line_height_style_dropdown_button_configurations.dart @@ -1,10 +1,12 @@ -import 'package:flutter/widgets.dart' show IconData, TextStyle, ValueChanged, VoidCallback; +import 'package:flutter/widgets.dart' + show IconData, TextStyle, ValueChanged, VoidCallback; import '../../../../widgets/toolbar/base_toolbar.dart'; import '../../../documents/attribute.dart'; import '../../../themes/quill_icon_theme.dart'; -class QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions extends QuillToolbarBaseButtonExtraOptions { +class QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions + extends QuillToolbarBaseButtonExtraOptions { const QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions({ required super.controller, required super.context, @@ -14,9 +16,10 @@ class QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions extends QuillT final Attribute currentValue; } -class QuillToolbarSelectLineHeightStyleDropdownButtonOptions extends QuillToolbarBaseButtonOptions< - QuillToolbarSelectLineHeightStyleDropdownButtonOptions, - QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions> { +class QuillToolbarSelectLineHeightStyleDropdownButtonOptions + extends QuillToolbarBaseButtonOptions< + QuillToolbarSelectLineHeightStyleDropdownButtonOptions, + QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions> { const QuillToolbarSelectLineHeightStyleDropdownButtonOptions({ super.afterButtonPressed, super.childBuilder, diff --git a/lib/src/models/config/toolbar/simple_toolbar_button_options.dart b/lib/src/models/config/toolbar/simple_toolbar_button_options.dart index beb1920c..0777701f 100644 --- a/lib/src/models/config/toolbar/simple_toolbar_button_options.dart +++ b/lib/src/models/config/toolbar/simple_toolbar_button_options.dart @@ -73,7 +73,7 @@ class QuillSimpleToolbarButtonOptions extends Equatable { const QuillToolbarSelectHeaderStyleButtonsOptions(), this.selectHeaderStyleDropdownButton = const QuillToolbarSelectHeaderStyleDropdownButtonOptions(), - this.selectLineHeightStyleDropdownButton = + this.selectLineHeightStyleDropdownButton = const QuillToolbarSelectLineHeightStyleDropdownButtonOptions(), this.linkStyle = const QuillToolbarLinkStyleButtonOptions(), this.linkStyle2 = const QuillToolbarLinkStyleButton2Options(), diff --git a/lib/src/models/documents/attribute.dart b/lib/src/models/documents/attribute.dart index ef1e63f2..bd87d024 100644 --- a/lib/src/models/documents/attribute.dart +++ b/lib/src/models/documents/attribute.dart @@ -58,9 +58,11 @@ class Attribute extends Equatable { static const BoldAttribute bold = BoldAttribute(); - static final ScriptAttribute subscript = ScriptAttribute(ScriptAttributes.sub); + static final ScriptAttribute subscript = + ScriptAttribute(ScriptAttributes.sub); - static final ScriptAttribute superscript = ScriptAttribute(ScriptAttributes.sup); + static final ScriptAttribute superscript = + ScriptAttribute(ScriptAttributes.sup); static const ItalicAttribute italic = ItalicAttribute(); @@ -180,16 +182,20 @@ class Attribute extends Equatable { static const Attribute h6 = HeaderAttribute(level: 6); /// "attributes":{"line-height": 1.0 } - static const Attribute lineHeightNormal = LineHeightAttribute(lineHeight: 1); + static const Attribute lineHeightNormal = + LineHeightAttribute(lineHeight: 1); /// "attributes":{"line-height": 1.15 } - static const Attribute lineHeightTight = LineHeightAttribute(lineHeight: 1.15); + static const Attribute lineHeightTight = + LineHeightAttribute(lineHeight: 1.15); /// "attributes":{"line-height": 1.5 } - static const Attribute lineHeightOneAndHalf = LineHeightAttribute(lineHeight: 1.5); + static const Attribute lineHeightOneAndHalf = + LineHeightAttribute(lineHeight: 1.5); /// "attributes":{"line-height": 2.0 } - static const Attribute lineHeightDouble = LineHeightAttribute(lineHeight: 2); + static const Attribute lineHeightDouble = + LineHeightAttribute(lineHeight: 2); // "attributes":{"align":"left"} static const Attribute leftAlignment = AlignAttribute('left'); @@ -277,7 +283,9 @@ class Attribute extends Equatable { if (identical(this, other)) return true; if (other is! Attribute) return false; final typedOther = other; - return key == typedOther.key && scope == typedOther.scope && value == typedOther.value; + return key == typedOther.key && + scope == typedOther.scope && + value == typedOther.value; } // This might not needed anymore because of equatable @@ -330,28 +338,34 @@ class LinkAttribute extends Attribute { } class ColorAttribute extends Attribute { - const ColorAttribute(String? val) : super('color', AttributeScope.inline, val); + const ColorAttribute(String? val) + : super('color', AttributeScope.inline, val); } class BackgroundAttribute extends Attribute { - const BackgroundAttribute(String? val) : super('background', AttributeScope.inline, val); + const BackgroundAttribute(String? val) + : super('background', AttributeScope.inline, val); } /// This is custom attribute for hint class PlaceholderAttribute extends Attribute { - const PlaceholderAttribute() : super('placeholder', AttributeScope.inline, true); + const PlaceholderAttribute() + : super('placeholder', AttributeScope.inline, true); } class HeaderAttribute extends Attribute { - const HeaderAttribute({int? level}) : super('header', AttributeScope.block, level); + const HeaderAttribute({int? level}) + : super('header', AttributeScope.block, level); } class LineHeightAttribute extends Attribute { - const LineHeightAttribute({double? lineHeight}) : super('line-height', AttributeScope.block, lineHeight); + const LineHeightAttribute({double? lineHeight}) + : super('line-height', AttributeScope.block, lineHeight); } class IndentAttribute extends Attribute { - const IndentAttribute({int? level}) : super('indent', AttributeScope.block, level); + const IndentAttribute({int? level}) + : super('indent', AttributeScope.block, level); } class AlignAttribute extends Attribute { @@ -371,19 +385,23 @@ class BlockQuoteAttribute extends Attribute { } class DirectionAttribute extends Attribute { - const DirectionAttribute(String? val) : super('direction', AttributeScope.block, val); + const DirectionAttribute(String? val) + : super('direction', AttributeScope.block, val); } class WidthAttribute extends Attribute { - const WidthAttribute(String? val) : super('width', AttributeScope.ignore, val); + const WidthAttribute(String? val) + : super('width', AttributeScope.ignore, val); } class HeightAttribute extends Attribute { - const HeightAttribute(String? val) : super('height', AttributeScope.ignore, val); + const HeightAttribute(String? val) + : super('height', AttributeScope.ignore, val); } class StyleAttribute extends Attribute { - const StyleAttribute(String? val) : super('style', AttributeScope.ignore, val); + const StyleAttribute(String? val) + : super('style', AttributeScope.ignore, val); } class TokenAttribute extends Attribute { @@ -391,7 +409,8 @@ class TokenAttribute extends Attribute { } class ScriptAttribute extends Attribute { - ScriptAttribute(ScriptAttributes? val) : super('script', AttributeScope.inline, val?.value); + ScriptAttribute(ScriptAttributes? val) + : super('script', AttributeScope.inline, val?.value); } enum ScriptAttributes { @@ -404,9 +423,11 @@ enum ScriptAttributes { } class ImageAttribute extends Attribute { - const ImageAttribute(String? url) : super('image', AttributeScope.embeds, url); + const ImageAttribute(String? url) + : super('image', AttributeScope.embeds, url); } class VideoAttribute extends Attribute { - const VideoAttribute(String? url) : super('video', AttributeScope.embeds, url); + const VideoAttribute(String? url) + : super('video', AttributeScope.embeds, url); } diff --git a/lib/src/widgets/others/default_styles.dart b/lib/src/widgets/others/default_styles.dart index a29f2ebf..e1a1a496 100644 --- a/lib/src/widgets/others/default_styles.dart +++ b/lib/src/widgets/others/default_styles.dart @@ -330,34 +330,34 @@ class DefaultStyles { const VerticalSpacing(0, 0), null, ), - lineHeightNormal: DefaultTextBlockStyle( + lineHeightNormal: DefaultTextBlockStyle( baseStyle.copyWith(height: 1.15), - const VerticalSpacing(0, 0), + const VerticalSpacing(0, 0), const VerticalSpacing(0, 0), null, ), - lineHeightTight: DefaultTextBlockStyle( + lineHeightTight: DefaultTextBlockStyle( baseStyle.copyWith(height: 1.30), const VerticalSpacing(0, 0), const VerticalSpacing(0, 0), null, ), - lineHeightOneAndHalf: DefaultTextBlockStyle( + lineHeightOneAndHalf: DefaultTextBlockStyle( baseStyle.copyWith(height: 1.55), const VerticalSpacing(0, 0), - const VerticalSpacing(0, 0), + const VerticalSpacing(0, 0), null, ), - lineHeightDouble: DefaultTextBlockStyle( + lineHeightDouble: DefaultTextBlockStyle( baseStyle.copyWith(height: 2), const VerticalSpacing(0, 0), - const VerticalSpacing(0, 0), + const VerticalSpacing(0, 0), null, ), paragraph: DefaultTextBlockStyle( baseStyle, - const VerticalSpacing(0, 0), - const VerticalSpacing(0, 0), + const VerticalSpacing(0, 0), + const VerticalSpacing(0, 0), null, ), bold: const TextStyle(fontWeight: FontWeight.bold), diff --git a/lib/src/widgets/quill/text_line.dart b/lib/src/widgets/quill/text_line.dart index 85623313..454dee42 100644 --- a/lib/src/widgets/quill/text_line.dart +++ b/lib/src/widgets/quill/text_line.dart @@ -301,7 +301,7 @@ class _TextLineState extends State { } textStyle = textStyle.merge(toMerge); - + final lineHeight = widget.line.style.attributes[Attribute.lineHeight.key]; final x = { Attribute.lineHeightNormal: defaultStyles.lineHeightNormal!.style, @@ -310,7 +310,8 @@ class _TextLineState extends State { Attribute.lineHeightDouble: defaultStyles.lineHeightDouble!.style, }; - textStyle = textStyle.merge(textStyle.copyWith(height: x[lineHeight]?.height)); + textStyle = + textStyle.merge(textStyle.copyWith(height: x[lineHeight]?.height)); textStyle = _applyCustomAttributes(textStyle, widget.line.style.attributes); diff --git a/lib/src/widgets/toolbar/buttons/select_line_height_dropdown_button.dart b/lib/src/widgets/toolbar/buttons/select_line_height_dropdown_button.dart index 114eaa60..06ee8a94 100644 --- a/lib/src/widgets/toolbar/buttons/select_line_height_dropdown_button.dart +++ b/lib/src/widgets/toolbar/buttons/select_line_height_dropdown_button.dart @@ -7,19 +7,24 @@ import '../../../models/documents/attribute.dart'; import '../base_button/base_value_button.dart'; import '../base_toolbar.dart'; -typedef QuillToolbarSelectLineHeightStyleDropdownBaseButton = QuillToolbarBaseButton< - QuillToolbarSelectLineHeightStyleDropdownButtonOptions, - QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions>; +typedef QuillToolbarSelectLineHeightStyleDropdownBaseButton + = QuillToolbarBaseButton< + QuillToolbarSelectLineHeightStyleDropdownButtonOptions, + QuillToolbarSelectLineHeightStyleDropdownButtonExtraOptions>; typedef QuillToolbarSelectLineHeightStyleDropdownBaseButtonsState< W extends QuillToolbarSelectLineHeightStyleDropdownButton> - = QuillToolbarCommonButtonState; -class QuillToolbarSelectLineHeightStyleDropdownButton extends QuillToolbarSelectLineHeightStyleDropdownBaseButton { +class QuillToolbarSelectLineHeightStyleDropdownButton + extends QuillToolbarSelectLineHeightStyleDropdownBaseButton { const QuillToolbarSelectLineHeightStyleDropdownButton({ required super.controller, - super.options = const QuillToolbarSelectLineHeightStyleDropdownButtonOptions(), + super.options = + const QuillToolbarSelectLineHeightStyleDropdownButtonOptions(), super.key, }); @@ -52,7 +57,8 @@ class _QuillToolbarSelectLineHeightStyleDropdownButtonState } @override - void didUpdateWidget(covariant QuillToolbarSelectLineHeightStyleDropdownButton oldWidget) { + void didUpdateWidget( + covariant QuillToolbarSelectLineHeightStyleDropdownButton oldWidget) { super.didUpdateWidget(oldWidget); if (oldWidget.controller == widget.controller) { return; @@ -73,12 +79,16 @@ class _QuillToolbarSelectLineHeightStyleDropdownButtonState } Attribute _getLineHeightValue() { - final attr = widget.controller.toolbarButtonToggler[Attribute.lineHeight.key]; + final attr = + widget.controller.toolbarButtonToggler[Attribute.lineHeight.key]; if (attr != null) { widget.controller.toolbarButtonToggler.remove(Attribute.lineHeight.key); return attr; } - return widget.controller.getSelectionStyle().attributes[Attribute.lineHeight.key] ?? Attribute.lineHeight; + return widget.controller + .getSelectionStyle() + .attributes[Attribute.lineHeight.key] ?? + Attribute.lineHeight; } String _label(Attribute attribute) { @@ -107,7 +117,8 @@ class _QuillToolbarSelectLineHeightStyleDropdownButtonState @override Widget build(BuildContext context) { final baseButtonConfigurations = context.quillToolbarBaseButtonOptions; - final childBuilder = widget.options.childBuilder ?? baseButtonConfigurations?.childBuilder; + final childBuilder = + widget.options.childBuilder ?? baseButtonConfigurations?.childBuilder; if (childBuilder != null) { return childBuilder( widget.options, diff --git a/lib/src/widgets/toolbar/simple_toolbar.dart b/lib/src/widgets/toolbar/simple_toolbar.dart index d65bfbad..a95b17de 100644 --- a/lib/src/widgets/toolbar/simple_toolbar.dart +++ b/lib/src/widgets/toolbar/simple_toolbar.dart @@ -31,7 +31,7 @@ class QuillSimpleToolbar extends StatelessWidget configurations.showItalicButton || configurations.showSmallButton || configurations.showUnderLineButton || - configurations.showLineHeightButton || + configurations.showLineHeightButton || configurations.showStrikeThrough || configurations.showInlineCode || configurations.showColorButton || @@ -196,13 +196,12 @@ class QuillSimpleToolbar extends StatelessWidget isButtonGroupShown[4] || isButtonGroupShown[5])) divider, - if (configurations.showLineHeightButton) - QuillToolbarSelectLineHeightStyleDropdownButton( - controller: globalController, - options: toolbarConfigurations - .buttonOptions.selectLineHeightStyleDropdownButton, - ), + QuillToolbarSelectLineHeightStyleDropdownButton( + controller: globalController, + options: toolbarConfigurations + .buttonOptions.selectLineHeightStyleDropdownButton, + ), if (configurations.showHeaderStyle) ...[ if (configurations.headerStyleType.isOriginal) QuillToolbarSelectHeaderStyleDropdownButton(