diff --git a/lib/src/widgets/toolbar.dart b/lib/src/widgets/toolbar.dart index 87ec770a..7c10582a 100644 --- a/lib/src/widgets/toolbar.dart +++ b/lib/src/widgets/toolbar.dart @@ -6,7 +6,6 @@ import '../models/themes/quill_custom_button.dart'; import '../models/themes/quill_dialog_theme.dart'; import '../models/themes/quill_icon_theme.dart'; import '../translations/toolbar.i18n.dart'; -import '../utils/font.dart'; import 'controller.dart'; import 'embeds.dart'; import 'toolbar/arrow_indicated_button_list.dart'; @@ -297,20 +296,6 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { tooltip: buttonTooltips[ToolbarButtons.fontSize], attribute: Attribute.size, controller: controller, - items: [ - for (MapEntry fontSize in fontSizes.entries) - PopupMenuItem( - key: ValueKey(fontSize.key), - value: fontSize.value, - child: Text(fontSize.key.toString(), - style: TextStyle( - color: fontSize.value == '0' ? Colors.red : null)), - ), - ], - onSelected: (newSize) { - controller.formatSelection(Attribute.fromKeyValue( - 'size', newSize == '0' ? null : getFontSize(newSize))); - }, rawItemsMap: fontSizes, afterButtonPressed: afterButtonPressed, ), diff --git a/lib/src/widgets/toolbar/quill_font_size_button.dart b/lib/src/widgets/toolbar/quill_font_size_button.dart index d3aa63c5..a6d76867 100644 --- a/lib/src/widgets/toolbar/quill_font_size_button.dart +++ b/lib/src/widgets/toolbar/quill_font_size_button.dart @@ -10,11 +10,11 @@ import '../controller.dart'; class QuillFontSizeButton extends StatefulWidget { const QuillFontSizeButton({ - required this.items, required this.rawItemsMap, required this.attribute, required this.controller, - required this.onSelected, + this.onSelected, + @Deprecated('It is not required because of `rawItemsMap`') this.items, this.iconSize = 40, this.fillColor, this.hoverElevation = 1, @@ -25,15 +25,17 @@ class QuillFontSizeButton extends StatefulWidget { this.padding, this.style, Key? key, - }) : super(key: key); + }) : assert(rawItemsMap.length > 0), + super(key: key); final double iconSize; final Color? fillColor; final double hoverElevation; final double highlightElevation; - final List> items; + @Deprecated('It is not required because of `rawItemsMap`') + final List>? items; final Map rawItemsMap; - final ValueChanged onSelected; + final ValueChanged? onSelected; final QuillIconTheme? iconTheme; final Attribute attribute; final QuillController controller; @@ -132,7 +134,18 @@ class _QuillFontSizeButtonState extends State { showMenu( context: context, elevation: 4, - items: widget.items, + items: [ + for (MapEntry fontSize in widget.rawItemsMap.entries) + PopupMenuItem( + key: ValueKey(fontSize.key), + value: fontSize.value, + child: Text( + fontSize.key.toString(), + style: + TextStyle(color: fontSize.value == '0' ? Colors.red : null), + ), + ), + ], position: position, shape: popupMenuTheme.shape, color: popupMenuTheme.color, @@ -145,7 +158,9 @@ class _QuillFontSizeButtonState extends State { setState(() { _currentValue = keyName ?? _defaultDisplayText; if (keyName != null) { - widget.onSelected(newValue); + widget.controller.formatSelection(Attribute.fromKeyValue( + 'size', newValue == '0' ? null : getFontSize(newValue))); + widget.onSelected?.call(newValue); } }); });