Convert FontSize to a Map to allow for named Font Size (#794)

pull/796/head
mark8044 3 years ago committed by GitHub
parent 62bc09d19a
commit b30fee9ae4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      lib/src/widgets/toolbar.dart
  2. 22
      lib/src/widgets/toolbar/quill_dropdown_button.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<String, int>? 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<String, int> fontSize in fontSizes.entries)
PopupMenuItem<int>(
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(

@ -5,6 +5,7 @@ class QuillDropdownButton<T> 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<T> extends StatefulWidget {
final double highlightElevation;
final T initialValue;
final List<PopupMenuEntry<T>> items;
final Map<String,int> rawitemsmap;
final ValueChanged<T> onSelected;
final QuillIconTheme? iconTheme;
@ -29,12 +31,12 @@ class QuillDropdownButton<T> extends StatefulWidget {
// ignore: deprecated_member_use_from_same_package
class _QuillDropdownButtonState<T> extends State<QuillDropdownButton<T>> {
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<T> extends State<QuillDropdownButton<T>> {
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)
],
),
),
);
);
}
}

Loading…
Cancel
Save