From 8bba10517033f35d4d608081c430e380020b3ae5 Mon Sep 17 00:00:00 2001 From: Aleksei <130981115+MacDeveloper1@users.noreply.github.com> Date: Wed, 6 Dec 2023 17:44:22 +0100 Subject: [PATCH] File refactoring --- .../buttons/dropdown_header_style.dart | 116 ++++++++++++++++++ .../toolbar/toolbar_configurations.dart | 20 +++ .../buttons/dropdown_header_style.dart | 110 ----------------- 3 files changed, 136 insertions(+), 110 deletions(-) create mode 100644 lib/src/models/config/toolbar/buttons/dropdown_header_style.dart diff --git a/lib/src/models/config/toolbar/buttons/dropdown_header_style.dart b/lib/src/models/config/toolbar/buttons/dropdown_header_style.dart new file mode 100644 index 00000000..238e7bba --- /dev/null +++ b/lib/src/models/config/toolbar/buttons/dropdown_header_style.dart @@ -0,0 +1,116 @@ +import 'package:flutter/material.dart'; + +import '../../../../widgets/controller.dart'; +import '../../../documents/attribute.dart'; +import '../../../themes/quill_icon_theme.dart'; +import '../../quill_configurations.dart'; + +class QuillToolbarSelectHeaderStyleDropdownButtonExtraOptions + extends QuillToolbarBaseButtonExtraOptions { + const QuillToolbarSelectHeaderStyleDropdownButtonExtraOptions({ + required this.currentValue, + required super.controller, + required super.context, + required super.onPressed, + }); + final Attribute currentValue; +} + +class QuillToolbarSelectHeaderStyleDropdownButtonOptions + extends QuillToolbarBaseButtonOptions< + QuillToolbarSelectHeaderStyleDropdownButtonOptions, + QuillToolbarSelectHeaderStyleDropdownButtonExtraOptions> { + const QuillToolbarSelectHeaderStyleDropdownButtonOptions({ + super.controller, + super.iconData, + super.afterButtonPressed, + super.tooltip, + super.iconTheme, + super.childBuilder, + this.iconSize, + this.iconButtonFactor, + this.fillColor, + this.hoverElevation = 1, + this.highlightElevation = 1, + this.rawItemsMap, + this.onSelected, + this.attributes, + this.padding, + this.style, + this.width, + this.initialValue, + this.labelOverflow = TextOverflow.visible, + this.itemHeight, + this.itemPadding, + this.defaultItemColor, + }); + + final double? iconSize; + final double? iconButtonFactor; + final Color? fillColor; + final double hoverElevation; + final double highlightElevation; + final Map? rawItemsMap; + final ValueChanged? onSelected; + final List? attributes; + final EdgeInsetsGeometry? padding; + final TextStyle? style; + final double? width; + final String? initialValue; + final TextOverflow labelOverflow; + final double? itemHeight; + final EdgeInsets? itemPadding; + final Color? defaultItemColor; + + QuillToolbarSelectHeaderStyleDropdownButtonOptions copyWith({ + Color? fillColor, + double? hoverElevation, + double? highlightElevation, + List>? items, + Map? rawItemsMap, + ValueChanged? onSelected, + List? attributes, + EdgeInsetsGeometry? padding, + TextStyle? style, + double? width, + String? initialValue, + TextOverflow? labelOverflow, + bool? renderFontFamilies, + bool? overrideTooltipByFontFamily, + double? itemHeight, + EdgeInsets? itemPadding, + Color? defaultItemColor, + double? iconSize, + double? iconButtonFactor, + // Add properties to override inherited properties + QuillController? controller, + IconData? iconData, + VoidCallback? afterButtonPressed, + String? tooltip, + QuillIconTheme? iconTheme, + }) { + return QuillToolbarSelectHeaderStyleDropdownButtonOptions( + attributes: attributes ?? this.attributes, + rawItemsMap: rawItemsMap ?? this.rawItemsMap, + controller: controller ?? this.controller, + iconData: iconData ?? this.iconData, + afterButtonPressed: afterButtonPressed ?? this.afterButtonPressed, + tooltip: tooltip ?? this.tooltip, + iconTheme: iconTheme ?? this.iconTheme, + onSelected: onSelected ?? this.onSelected, + padding: padding ?? this.padding, + style: style ?? this.style, + width: width ?? this.width, + initialValue: initialValue ?? this.initialValue, + labelOverflow: labelOverflow ?? this.labelOverflow, + itemHeight: itemHeight ?? this.itemHeight, + itemPadding: itemPadding ?? this.itemPadding, + defaultItemColor: defaultItemColor ?? this.defaultItemColor, + iconSize: iconSize ?? this.iconSize, + iconButtonFactor: iconButtonFactor ?? this.iconButtonFactor, + fillColor: fillColor ?? this.fillColor, + hoverElevation: hoverElevation ?? this.hoverElevation, + highlightElevation: highlightElevation ?? this.highlightElevation, + ); + } +} diff --git a/lib/src/models/config/toolbar/toolbar_configurations.dart b/lib/src/models/config/toolbar/toolbar_configurations.dart index e4ccf4ad..f6ed5f2f 100644 --- a/lib/src/models/config/toolbar/toolbar_configurations.dart +++ b/lib/src/models/config/toolbar/toolbar_configurations.dart @@ -10,6 +10,7 @@ import 'buttons/base.dart'; import 'buttons/clear_format.dart'; import 'buttons/color.dart'; import 'buttons/custom_button.dart'; +import 'buttons/dropdown_header_style.dart'; import 'buttons/font_family.dart'; import 'buttons/font_size.dart'; import 'buttons/history.dart'; @@ -37,6 +38,7 @@ export './buttons/link_style2.dart'; export './buttons/search.dart'; export './buttons/select_alignment.dart'; export './buttons/select_header_style.dart'; +export './buttons/dropdown_header_style.dart'; export './buttons/toggle_check_list.dart'; export './buttons/toggle_style.dart'; @@ -63,6 +65,17 @@ enum LinkStyleType { bool get isAlternative => this == LinkStyleType.alternative; } +enum HeaderStyleType { + /// Defines the original [QuillToolbarSelectHeaderStyleButtons]. + original, + + /// Defines the alternative [QuillToolbarSelectHeaderStyleDropdownButton]. + dropdown; + + bool get isOriginal => this == HeaderStyleType.original; + bool get isDropdown => this == HeaderStyleType.dropdown; +} + /// The configurations for the toolbar widget of flutter quill @immutable class QuillToolbarConfigurations extends QuillSharedToolbarProperties { @@ -105,6 +118,7 @@ class QuillToolbarConfigurations extends QuillSharedToolbarProperties { this.showSubscript = true, this.showSuperscript = true, this.linkStyleType = LinkStyleType.original, + this.headerStyleType = HeaderStyleType.original, super.customButtons = const [], /// The decoration to use for the toolbar. @@ -208,6 +222,9 @@ class QuillToolbarConfigurations extends QuillSharedToolbarProperties { /// Defines which dialog is used for applying link attribute. final LinkStyleType linkStyleType; + /// Defines which dialog is used for applying header attribute. + final HeaderStyleType headerStyleType; + @override List get props => [ buttonOptions, @@ -255,6 +272,8 @@ class QuillToolbarButtonOptions extends Equatable { this.search = const QuillToolbarSearchButtonOptions(), this.selectHeaderStyleButtons = const QuillToolbarSelectHeaderStyleButtonsOptions(), + this.headerStyleButton = + const QuillToolbarSelectHeaderStyleDropdownButtonOptions(), this.linkStyle = const QuillToolbarLinkStyleButtonOptions(), this.linkStyle2 = const QuillToolbarLinkStyleButton2Options(), this.customButtons = const QuillToolbarCustomButtonOptions(), @@ -300,6 +319,7 @@ class QuillToolbarButtonOptions extends Equatable { /// for all the header style buttons and not just one, you still /// can customize it and you also have child builder final QuillToolbarSelectHeaderStyleButtonsOptions selectHeaderStyleButtons; + final QuillToolbarSelectHeaderStyleDropdownButtonOptions headerStyleButton; final QuillToolbarLinkStyleButtonOptions linkStyle; final QuillToolbarLinkStyleButton2Options linkStyle2; diff --git a/lib/src/widgets/toolbar/buttons/dropdown_header_style.dart b/lib/src/widgets/toolbar/buttons/dropdown_header_style.dart index 6eb92ab1..5745763c 100644 --- a/lib/src/widgets/toolbar/buttons/dropdown_header_style.dart +++ b/lib/src/widgets/toolbar/buttons/dropdown_header_style.dart @@ -4,116 +4,6 @@ import '../../../../flutter_quill.dart'; import '../../../../translations.dart'; import '../../../utils/widgets.dart'; -class QuillToolbarSelectHeaderStyleDropdownButtonExtraOptions - extends QuillToolbarBaseButtonExtraOptions { - const QuillToolbarSelectHeaderStyleDropdownButtonExtraOptions({ - required this.currentValue, - required super.controller, - required super.context, - required super.onPressed, - }); - final Attribute currentValue; -} - -class QuillToolbarSelectHeaderStyleDropdownButtonOptions - extends QuillToolbarBaseButtonOptions< - QuillToolbarSelectHeaderStyleDropdownButtonOptions, - QuillToolbarSelectHeaderStyleDropdownButtonExtraOptions> { - const QuillToolbarSelectHeaderStyleDropdownButtonOptions({ - super.controller, - super.iconData, - super.afterButtonPressed, - super.tooltip, - super.iconTheme, - super.childBuilder, - this.iconSize, - this.iconButtonFactor, - this.fillColor, - this.hoverElevation = 1, - this.highlightElevation = 1, - this.rawItemsMap, - this.onSelected, - this.attributes, - this.padding, - this.style, - this.width, - this.initialValue, - this.labelOverflow = TextOverflow.visible, - this.itemHeight, - this.itemPadding, - this.defaultItemColor, - }); - - final double? iconSize; - final double? iconButtonFactor; - final Color? fillColor; - final double hoverElevation; - final double highlightElevation; - final Map? rawItemsMap; - final ValueChanged? onSelected; - final List? attributes; - final EdgeInsetsGeometry? padding; - final TextStyle? style; - final double? width; - final String? initialValue; - final TextOverflow labelOverflow; - final double? itemHeight; - final EdgeInsets? itemPadding; - final Color? defaultItemColor; - - QuillToolbarSelectHeaderStyleDropdownButtonOptions copyWith({ - Color? fillColor, - double? hoverElevation, - double? highlightElevation, - List>? items, - Map? rawItemsMap, - ValueChanged? onSelected, - List? attributes, - EdgeInsetsGeometry? padding, - TextStyle? style, - double? width, - String? initialValue, - TextOverflow? labelOverflow, - bool? renderFontFamilies, - bool? overrideTooltipByFontFamily, - double? itemHeight, - EdgeInsets? itemPadding, - Color? defaultItemColor, - double? iconSize, - double? iconButtonFactor, - // Add properties to override inherited properties - QuillController? controller, - IconData? iconData, - VoidCallback? afterButtonPressed, - String? tooltip, - QuillIconTheme? iconTheme, - }) { - return QuillToolbarSelectHeaderStyleDropdownButtonOptions( - attributes: attributes ?? this.attributes, - rawItemsMap: rawItemsMap ?? this.rawItemsMap, - controller: controller ?? this.controller, - iconData: iconData ?? this.iconData, - afterButtonPressed: afterButtonPressed ?? this.afterButtonPressed, - tooltip: tooltip ?? this.tooltip, - iconTheme: iconTheme ?? this.iconTheme, - onSelected: onSelected ?? this.onSelected, - padding: padding ?? this.padding, - style: style ?? this.style, - width: width ?? this.width, - initialValue: initialValue ?? this.initialValue, - labelOverflow: labelOverflow ?? this.labelOverflow, - itemHeight: itemHeight ?? this.itemHeight, - itemPadding: itemPadding ?? this.itemPadding, - defaultItemColor: defaultItemColor ?? this.defaultItemColor, - iconSize: iconSize ?? this.iconSize, - iconButtonFactor: iconButtonFactor ?? this.iconButtonFactor, - fillColor: fillColor ?? this.fillColor, - hoverElevation: hoverElevation ?? this.hoverElevation, - highlightElevation: highlightElevation ?? this.highlightElevation, - ); - } -} - class QuillToolbarSelectHeaderStyleDropdownButton extends StatefulWidget { const QuillToolbarSelectHeaderStyleDropdownButton({ required this.controller,