Fix init of `headerTextStyles`

pull/1575/head
Aleksei 1 year ago
parent a9711b8ce9
commit 520a4e4aac
  1. 19
      lib/src/widgets/toolbar/buttons/dropdown_header_style.dart

@ -37,7 +37,7 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
Attribute.h6: context.loc.heading6, Attribute.h6: context.loc.heading6,
}; };
late final Map<Attribute, TextStyle> _headerTextStyles; Map<Attribute, TextStyle>? _headerTextStyles;
QuillToolbarSelectHeaderStyleDropdownButtonOptions get options { QuillToolbarSelectHeaderStyleDropdownButtonOptions get options {
return widget.options; return widget.options;
@ -100,10 +100,9 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
} }
@override @override
void initState() { void didChangeDependencies() {
super.initState(); super.didChangeDependencies();
controller.addListener(_didChangeEditingValue); if (_headerTextStyles == null) {
_selectedAttribute = _getHeaderValue();
final defaultStyles = QuillStyles.getStyles(context, false); final defaultStyles = QuillStyles.getStyles(context, false);
_headerTextStyles = { _headerTextStyles = {
Attribute.h1: defaultStyles!.h1!.style, Attribute.h1: defaultStyles!.h1!.style,
@ -114,6 +113,14 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
Attribute.h6: defaultStyles.h6!.style, Attribute.h6: defaultStyles.h6!.style,
}; };
} }
}
@override
void initState() {
super.initState();
controller.addListener(_didChangeEditingValue);
_selectedAttribute = _getHeaderValue();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -244,7 +251,7 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState
header.value, header.value,
style: TextStyle( style: TextStyle(
fontSize: options.renderItemTextStyle fontSize: options.renderItemTextStyle
? _headerTextStyles[header.key]?.fontSize ?? ? _headerTextStyles![header.key]!.fontSize ??
DefaultTextStyle.of(context).style.fontSize ?? DefaultTextStyle.of(context).style.fontSize ??
14 14
: null, : null,

Loading…
Cancel
Save