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

@ -37,6 +37,8 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
Attribute.h6: context.loc.heading6,
};
late final Map<Attribute, TextStyle> _headerTextStyles;
QuillToolbarSelectHeaderStyleDropdownButtonOptions get options {
return widget.options;
}
@ -102,6 +104,15 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
super.initState();
controller.addListener(_didChangeEditingValue);
_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
@ -232,7 +243,12 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
child: Text(
header.value,
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
: null,
),

Loading…
Cancel
Save