feat: Display the current font size

pull/1831/head
coolswood 1 year ago
parent b547e281c9
commit e8af5da733
  1. 42
      lib/src/widgets/toolbar/buttons/font_size_button.dart

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart';
import '../../../../extensions.dart'; import '../../../../extensions.dart';
@ -37,6 +38,7 @@ class QuillToolbarFontSizeButton extends StatefulWidget {
class QuillToolbarFontSizeButtonState class QuillToolbarFontSizeButtonState
extends State<QuillToolbarFontSizeButton> { extends State<QuillToolbarFontSizeButton> {
final _menuController = MenuController(); final _menuController = MenuController();
Style get _selectionStyle => controller.getSelectionStyle();
String _currentValue = ''; String _currentValue = '';
QuillToolbarFontSizeButtonOptions get options { QuillToolbarFontSizeButtonOptions get options {
@ -78,8 +80,44 @@ class QuillToolbarFontSizeButtonState
_currentValue = _defaultDisplayText; _currentValue = _defaultDisplayText;
} }
@override
void didUpdateWidget(covariant QuillToolbarFontSizeButton oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller != controller) {
oldWidget.controller.removeListener(_didChangeEditingValue);
controller.addListener(_didChangeEditingValue);
_currentValue = _defaultDisplayText;
}
}
@override
void initState() {
super.initState();
controller.addListener(_didChangeEditingValue);
}
void _didChangeEditingValue() {
final selectedFontSize =
_selectionStyle.attributes[Attribute.size.key]?.value;
if (selectedFontSize == null) {
setState(() {
_currentValue = _defaultDisplayText;
});
return;
}
setState(() {
_currentValue = selectedFontSize is double
? selectedFontSize.toInt().toString()
: selectedFontSize;
});
}
@override @override
void dispose() { void dispose() {
controller.removeListener(_didChangeEditingValue);
super.dispose(); super.dispose();
} }
@ -224,9 +262,7 @@ class QuillToolbarFontSizeButtonState
enabled: hasFinalWidth, enabled: hasFinalWidth,
wrapper: (child) => Expanded(child: child), wrapper: (child) => Expanded(child: child),
child: Text( child: Text(
getLabel(widget.controller.selectedFontSize?.key) ?? getLabel(_currentValue) ?? '',
getLabel(_currentValue) ??
'',
overflow: options.labelOverflow, overflow: options.labelOverflow,
style: options.style ?? style: options.style ??
TextStyle( TextStyle(

Loading…
Cancel
Save