Fix list button toggle

pull/13/head
singerdmx 4 years ago
parent 665da6a89c
commit 1fd5fbad7d
  1. 28
      lib/widgets/toolbar.dart

@ -198,27 +198,36 @@ class _ToggleStyleButtonState extends State<ToggleStyleButton> {
void _didChangeEditingValue() { void _didChangeEditingValue() {
setState(() { setState(() {
_isToggled = widget.controller _isToggled =
.getSelectionStyle() _getIsToggled(widget.controller.getSelectionStyle().attributes);
.attributes
.containsKey(widget.attribute.key);
}); });
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_isToggled = _selectionStyle.attributes.containsKey(widget.attribute.key); _isToggled = _getIsToggled(_selectionStyle.attributes);
widget.controller.addListener(_didChangeEditingValue); widget.controller.addListener(_didChangeEditingValue);
} }
bool _getIsToggled(Map<String, Attribute> attrs) {
if (widget.attribute.key == Attribute.list.key) {
Attribute attribute = attrs[widget.attribute.key];
if (attribute == null) {
return false;
}
return attribute.value == widget.attribute.value;
}
return attrs.containsKey(widget.attribute.key);
}
@override @override
void didUpdateWidget(covariant ToggleStyleButton oldWidget) { void didUpdateWidget(covariant ToggleStyleButton oldWidget) {
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
if (oldWidget.controller != widget.controller) { if (oldWidget.controller != widget.controller) {
oldWidget.controller.removeListener(_didChangeEditingValue); oldWidget.controller.removeListener(_didChangeEditingValue);
widget.controller.addListener(_didChangeEditingValue); widget.controller.addListener(_didChangeEditingValue);
_isToggled = _selectionStyle.attributes.containsKey(widget.attribute.key); _isToggled = _getIsToggled(_selectionStyle.attributes);
} }
} }
@ -603,8 +612,11 @@ class IndentButton extends StatefulWidget {
final QuillController controller; final QuillController controller;
final bool isIncrease; final bool isIncrease;
IndentButton({Key key, @required this.icon, @required this.controller IndentButton(
, @required this.isIncrease}) {Key key,
@required this.icon,
@required this.controller,
@required this.isIncrease})
: assert(icon != null), : assert(icon != null),
assert(controller != null), assert(controller != null),
assert(isIncrease != null), assert(isIncrease != null),

Loading…
Cancel
Save