Implement `renderItemTextStyle`

pull/1575/head
Aleksei 1 year ago
parent e712890456
commit a9711b8ce9
  1. 5
      lib/src/models/config/toolbar/buttons/dropdown_header_style.dart
  2. 18
      lib/src/widgets/toolbar/buttons/dropdown_header_style.dart

@ -42,6 +42,7 @@ class QuillToolbarSelectHeaderStyleDropdownButtonOptions
this.itemHeight, this.itemHeight,
this.itemPadding, this.itemPadding,
this.defaultItemColor, this.defaultItemColor,
this.renderItemTextStyle = false,
}); });
final double? iconSize; final double? iconSize;
@ -59,6 +60,7 @@ class QuillToolbarSelectHeaderStyleDropdownButtonOptions
final double? itemHeight; final double? itemHeight;
final EdgeInsets? itemPadding; final EdgeInsets? itemPadding;
final Color? defaultItemColor; final Color? defaultItemColor;
final bool renderItemTextStyle;
QuillToolbarSelectHeaderStyleDropdownButtonOptions copyWith({ QuillToolbarSelectHeaderStyleDropdownButtonOptions copyWith({
Color? fillColor, Color? fillColor,
@ -79,12 +81,12 @@ class QuillToolbarSelectHeaderStyleDropdownButtonOptions
Color? defaultItemColor, Color? defaultItemColor,
double? iconSize, double? iconSize,
double? iconButtonFactor, double? iconButtonFactor,
// Add properties to override inherited properties
QuillController? controller, QuillController? controller,
IconData? iconData, IconData? iconData,
VoidCallback? afterButtonPressed, VoidCallback? afterButtonPressed,
String? tooltip, String? tooltip,
QuillIconTheme? iconTheme, QuillIconTheme? iconTheme,
bool? renderItemTextStyle,
}) { }) {
return QuillToolbarSelectHeaderStyleDropdownButtonOptions( return QuillToolbarSelectHeaderStyleDropdownButtonOptions(
attributes: attributes ?? this.attributes, attributes: attributes ?? this.attributes,
@ -107,6 +109,7 @@ class QuillToolbarSelectHeaderStyleDropdownButtonOptions
fillColor: fillColor ?? this.fillColor, fillColor: fillColor ?? this.fillColor,
hoverElevation: hoverElevation ?? this.hoverElevation, hoverElevation: hoverElevation ?? this.hoverElevation,
highlightElevation: highlightElevation ?? this.highlightElevation, highlightElevation: highlightElevation ?? this.highlightElevation,
renderItemTextStyle: renderItemTextStyle ?? this.renderItemTextStyle,
); );
} }
} }

@ -37,6 +37,8 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
Attribute.h6: context.loc.heading6, Attribute.h6: context.loc.heading6,
}; };
late final Map<Attribute, TextStyle> _headerTextStyles;
QuillToolbarSelectHeaderStyleDropdownButtonOptions get options { QuillToolbarSelectHeaderStyleDropdownButtonOptions get options {
return widget.options; return widget.options;
} }
@ -102,6 +104,15 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
super.initState(); super.initState();
controller.addListener(_didChangeEditingValue); controller.addListener(_didChangeEditingValue);
_selectedAttribute = _getHeaderValue(); _selectedAttribute = _getHeaderValue();
final defaultStyles = QuillStyles.getStyles(context, false);
_headerTextStyles = {
Attribute.h1: defaultStyles!.h1!.style,
Attribute.h2: defaultStyles.h2!.style,
Attribute.h3: defaultStyles.h3!.style,
Attribute.h4: defaultStyles.h4!.style,
Attribute.h5: defaultStyles.h5!.style,
Attribute.h6: defaultStyles.h6!.style,
};
} }
@override @override
@ -232,7 +243,12 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
child: Text( child: Text(
header.value, header.value,
style: TextStyle( style: TextStyle(
color: header.key == Attribute.header fontSize: options.renderItemTextStyle
? _headerTextStyles[header.key]?.fontSize ??
DefaultTextStyle.of(context).style.fontSize ??
14
: null,
color: header.key == _selectedAttribute
? options.defaultItemColor ? options.defaultItemColor
: null, : null,
), ),

Loading…
Cancel
Save