diff --git a/lib/src/widgets/quill/quill_controller.dart b/lib/src/widgets/quill/quill_controller.dart index ebbaa7d6..1a2634e4 100644 --- a/lib/src/widgets/quill/quill_controller.dart +++ b/lib/src/widgets/quill/quill_controller.dart @@ -14,7 +14,6 @@ import '../../models/structs/doc_change.dart'; import '../../models/structs/image_url.dart'; import '../../models/structs/offset_value.dart'; import '../../utils/delta.dart'; -import '../toolbar/buttons/toggle_style_button.dart'; typedef ReplaceTextCallback = bool Function(int index, int len, Object? data); typedef DeleteCallback = void Function(int cursorPosition, bool forward); @@ -67,40 +66,6 @@ class QuillController extends ChangeNotifier { notifyListeners(); } - // Thoses are the values that the user selects and not the one - // from the current line - - /// The current font family, null to use the default one - MapEntry? _selectedFontFamily; - - /// The current font family, null to use the default one - MapEntry? get selectedFontFamily => _selectedFontFamily; - - void selectFontFamily(MapEntry? newFontFamily) { - _selectedFontFamily = newFontFamily; - } - - /// The current font size, null to use the default one - MapEntry? _selectedFontSize; - - /// The current font size, null to use the default one - MapEntry? get selectedFontSize => _selectedFontSize; - - void selectFontSize(MapEntry? newFontSize) { - _selectedFontSize = newFontSize; - } - - /// For the [QuillToolbarToggleStyleButton] - final Map _selectedStyles = {}; - - /// For the [QuillToolbarToggleStyleButton] - Map get selectedStyles => _selectedStyles; - - /// For the [QuillToolbarToggleStyleButton] - void selectStyle(Attribute attribute, bool value) { - _selectedStyles[attribute] = value; - } - /// Tells whether to keep or reset the [toggledStyle] /// when user adds a new line. final bool keepStyleOnNewLine; diff --git a/lib/src/widgets/toolbar/buttons/font_family_button.dart b/lib/src/widgets/toolbar/buttons/font_family_button.dart index 480e4801..5c583d2b 100644 --- a/lib/src/widgets/toolbar/buttons/font_family_button.dart +++ b/lib/src/widgets/toolbar/buttons/font_family_button.dart @@ -67,12 +67,10 @@ class QuillToolbarFontFamilyButtonState @override void didUpdateWidget(covariant QuillToolbarFontFamilyButton oldWidget) { super.didUpdateWidget(oldWidget); - if (oldWidget.controller == controller) { - return; + if (oldWidget.controller != controller) { + oldWidget.controller.removeListener(_didChangeEditingValue); + controller.addListener(_didChangeEditingValue); } - controller - ..removeListener(_didChangeEditingValue) - ..addListener(_didChangeEditingValue); } @override @@ -218,13 +216,7 @@ class QuillToolbarFontFamilyButtonState options.onSelected?.call(newValue); } }); - - if (fontFamily.value == 'Clear') { - controller.selectFontFamily(null); - return; - } - controller.selectFontFamily(fontFamily); - }, + }, child: Text( fontFamily.key.toString(), style: TextStyle( diff --git a/lib/src/widgets/toolbar/buttons/font_size_button.dart b/lib/src/widgets/toolbar/buttons/font_size_button.dart index 4c00a07a..e3be38da 100644 --- a/lib/src/widgets/toolbar/buttons/font_size_button.dart +++ b/lib/src/widgets/toolbar/buttons/font_size_button.dart @@ -91,12 +91,10 @@ class QuillToolbarFontSizeButtonState @override void didUpdateWidget(covariant QuillToolbarFontSizeButton oldWidget) { super.didUpdateWidget(oldWidget); - if (oldWidget.controller == controller) { - return; + if (oldWidget.controller != controller) { + oldWidget.controller.removeListener(_didChangeEditingValue); + controller.addListener(_didChangeEditingValue); } - controller - ..removeListener(_didChangeEditingValue) - ..addListener(_didChangeEditingValue); } @override @@ -208,12 +206,6 @@ class QuillToolbarFontSizeButtonState options.onSelected?.call(newValue); } }); - - if (fontSize.value == '0') { - controller.selectFontSize(null); - return; - } - controller.selectFontSize(fontSize); }, child: Text( fontSize.key.toString(), diff --git a/lib/src/widgets/toolbar/buttons/toggle_style_button.dart b/lib/src/widgets/toolbar/buttons/toggle_style_button.dart index f93e79a1..2f242ea9 100644 --- a/lib/src/widgets/toolbar/buttons/toggle_style_button.dart +++ b/lib/src/widgets/toolbar/buttons/toggle_style_button.dart @@ -218,12 +218,11 @@ class QuillToolbarToggleStyleButtonState void _toggleAttribute() { controller - ..formatSelection( + .formatSelection( (_isToggled ?? false) ? Attribute.clone(widget.attribute, null) : widget.attribute, - ) - ..selectStyle(widget.attribute, _isToggled ?? false); + ); } }