From 520a4e4aacfc533ca58c5b488542f8218a18d378 Mon Sep 17 00:00:00 2001 From: Aleksei <130981115+MacDeveloper1@users.noreply.github.com> Date: Thu, 7 Dec 2023 10:29:57 +0100 Subject: [PATCH] Fix init of `headerTextStyles` --- .../buttons/dropdown_header_style.dart | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/src/widgets/toolbar/buttons/dropdown_header_style.dart b/lib/src/widgets/toolbar/buttons/dropdown_header_style.dart index 25cac749..1abb91ca 100644 --- a/lib/src/widgets/toolbar/buttons/dropdown_header_style.dart +++ b/lib/src/widgets/toolbar/buttons/dropdown_header_style.dart @@ -37,7 +37,7 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState Attribute.h6: context.loc.heading6, }; - late final Map _headerTextStyles; + Map? _headerTextStyles; QuillToolbarSelectHeaderStyleDropdownButtonOptions get options { return widget.options; @@ -99,20 +99,27 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState } } + @override + void didChangeDependencies() { + super.didChangeDependencies(); + if (_headerTextStyles == null) { + 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 void initState() { 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 @@ -244,7 +251,7 @@ class _QuillToolbarSelectHeaderStyleDropdownButtonState header.value, style: TextStyle( fontSize: options.renderItemTextStyle - ? _headerTextStyles[header.key]?.fontSize ?? + ? _headerTextStyles![header.key]!.fontSize ?? DefaultTextStyle.of(context).style.fontSize ?? 14 : null,