Optimize `QuillFontSizeButton`

pull/1179/head
BambinoUA 2 years ago
parent 4723d687c7
commit 1176e9b4d9
  1. 15
      lib/src/widgets/toolbar.dart
  2. 29
      lib/src/widgets/toolbar/quill_font_size_button.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<String, String> fontSize in fontSizes.entries)
PopupMenuItem<String>(
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,
),

@ -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<PopupMenuEntry<String>> items;
@Deprecated('It is not required because of `rawItemsMap`')
final List<PopupMenuEntry<String>>? items;
final Map<String, String> rawItemsMap;
final ValueChanged<String> onSelected;
final ValueChanged<String>? onSelected;
final QuillIconTheme? iconTheme;
final Attribute attribute;
final QuillController controller;
@ -132,7 +134,18 @@ class _QuillFontSizeButtonState extends State<QuillFontSizeButton> {
showMenu<String>(
context: context,
elevation: 4,
items: widget.items,
items: [
for (MapEntry<String, String> fontSize in widget.rawItemsMap.entries)
PopupMenuItem<String>(
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<QuillFontSizeButton> {
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);
}
});
});

Loading…
Cancel
Save