diff --git a/lib/src/widgets/toolbar.dart b/lib/src/widgets/toolbar.dart index c3277865..9b9c587c 100644 --- a/lib/src/widgets/toolbar.dart +++ b/lib/src/widgets/toolbar.dart @@ -110,8 +110,8 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { WebImagePickImpl? webImagePickImpl, WebVideoPickImpl? webVideoPickImpl, - ///List of font sizes in [int] - List? fontSizeValues, + ///Map of font sizes in [int] + Map? fontSizeValues, int? initialFontSizeValue, ///The theme to use for the icons in the toolbar, uses type [QuillIconTheme] @@ -152,7 +152,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { //default font size values final fontSizes = - fontSizeValues ?? [10, 12, 14, 16, 18, 20, 24, 28, 32, 48]; + fontSizeValues ?? {'10':10, '12':12, '14':14, '16':16, '18':18, '20':20, '24':24, '28':28, '32':32, '48':48}; return QuillToolbar( key: key, @@ -181,12 +181,13 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { if (showFontSize) QuillDropdownButton( iconTheme: iconTheme, - height: toolbarIconSize * 2, + height: (toolbarIconSize * 2)-(toolbarIconSize / 3), items: [ - for (var fontSize in fontSizes) + for(MapEntry fontSize in fontSizes.entries) PopupMenuItem( - value: fontSize, - child: Text(fontSize.toString()), + key: ValueKey(fontSize.key), + value: fontSize.value, + child: Text(fontSize.key.toString()), ), ], onSelected: (newSize) { @@ -195,7 +196,8 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { .formatSelection(Attribute.fromKeyValue('size', newSize)); } }, - initialValue: fontSizes[initialFontSizeValue ?? 0], + rawitemsmap: fontSizes, + initialValue: (initialFontSizeValue != null) && (initialFontSizeValue <= fontSizes.length - 1) ? initialFontSizeValue : 0, ), if (showBoldButton) ToggleStyleButton( diff --git a/lib/src/widgets/toolbar/quill_dropdown_button.dart b/lib/src/widgets/toolbar/quill_dropdown_button.dart index 94642e5d..55900415 100644 --- a/lib/src/widgets/toolbar/quill_dropdown_button.dart +++ b/lib/src/widgets/toolbar/quill_dropdown_button.dart @@ -5,6 +5,7 @@ class QuillDropdownButton extends StatefulWidget { const QuillDropdownButton({ required this.initialValue, required this.items, + required this.rawitemsmap, required this.onSelected, this.height = 40, this.fillColor, @@ -20,6 +21,7 @@ class QuillDropdownButton extends StatefulWidget { final double highlightElevation; final T initialValue; final List> items; + final Map rawitemsmap; final ValueChanged onSelected; final QuillIconTheme? iconTheme; @@ -29,12 +31,12 @@ class QuillDropdownButton extends StatefulWidget { // ignore: deprecated_member_use_from_same_package class _QuillDropdownButtonState extends State> { - int _currentValue = 0; + String _currentValue = ''; @override void initState() { super.initState(); - _currentValue = widget.initialValue as int; + _currentValue = widget.rawitemsmap.keys.elementAt(widget.initialValue as int); } @override @@ -87,25 +89,23 @@ class _QuillDropdownButtonState extends State> { return null; } setState(() { - _currentValue = newValue as int; + _currentValue = widget.rawitemsmap.entries.firstWhere((element) => element.value==newValue, orElse: () => widget.rawitemsmap.entries.first).key; widget.onSelected(newValue); }); }); } Widget _buildContent(BuildContext context) { - return ConstrainedBox( - constraints: const BoxConstraints.tightFor(width: 60), - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 8), + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 10), child: Row( + mainAxisSize: MainAxisSize.min, children: [ Text(_currentValue.toString()), - Expanded(child: Container()), - const Icon(Icons.arrow_drop_down, size: 15) + SizedBox(width:6), + const Icon(Icons.arrow_drop_down, size: 17) ], ), - ), - ); + ); } }