Value setting Stateful toolbar buttons derive from base class

pull/1986/head
AtlasAutocode 12 months ago
parent ce5eb86b10
commit eda74792ec
  1. 43
      lib/src/widgets/quill/quill_controller.dart
  2. 83
      lib/src/widgets/toolbar/base_button/stateful_base_button_ex.dart

@ -72,6 +72,49 @@ class QuillController extends ChangeNotifier {
notifyListeners();
}
// Those 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
@Deprecated('No longer used')
MapEntry<String, String>? _selectedFontFamily;
/// The current font family, null to use the default one
@Deprecated('No longer used')
MapEntry<String, String>? get selectedFontFamily => _selectedFontFamily;
@Deprecated('No longer used')
void selectFontFamily(MapEntry<String, String>? newFontFamily) {
_selectedFontFamily = newFontFamily;
}
/// The current font size, null to use the default one
@Deprecated('No longer used')
MapEntry<String, String>? _selectedFontSize;
/// The current font size, null to use the default one
@Deprecated('No longer used')
MapEntry<String, String>? get selectedFontSize => _selectedFontSize;
@Deprecated('No longer used')
void selectFontSize(MapEntry<String, String>? newFontSize) {
_selectedFontSize = newFontSize;
}
/// For the [QuillToolbarToggleStyleButton]
@Deprecated('No longer used')
final Map<Attribute, bool?> _selectedStyles = {};
/// For the [QuillToolbarToggleStyleButton]
@Deprecated('No longer used')
Map<Attribute, bool?> get selectedStyles => _selectedStyles;
/// For the [QuillToolbarToggleStyleButton]
@Deprecated('No longer used')
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;

@ -0,0 +1,83 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../../../flutter_quill.dart';
/// The [T] is the options for the button
/// The [E] is the extra options for the button
abstract class QuillToolbarStatefulBaseButton<
T extends QuillToolbarBaseButtonOptions<T, E>,
E extends QuillToolbarBaseButtonExtraOptions> extends StatefulWidget {
const QuillToolbarStatefulBaseButton(
{required this.controller, required this.options, super.key});
final T options;
final QuillController controller;
}
/// The [W] is the widget that creates this State
abstract class QuillToolbarBaseButtonState<
W extends QuillToolbarStatefulBaseButton<T, E>,
T extends QuillToolbarBaseButtonOptions<T, E>,
E extends QuillToolbarBaseButtonExtraOptions> extends State<W> {
T get options => widget.options;
QuillController get controller => widget.controller;
@override
void initState() {
super.initState();
controller.addListener(didChangeEditingValue);
}
void didChangeEditingValue();
@override
void dispose() {
controller.removeListener(didChangeEditingValue);
super.dispose();
}
@override
void didUpdateWidget(covariant W oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.controller != controller) {
oldWidget.controller.removeListener(didChangeEditingValue);
controller.addListener(didChangeEditingValue);
}
}
String get defaultTooltip;
String get tooltip {
return options.tooltip ??
context.quillToolbarBaseButtonOptions?.tooltip ??
defaultTooltip;
}
double get iconSize {
final baseFontSize = context.quillToolbarBaseButtonOptions?.iconSize;
final iconSize = options.iconSize;
return iconSize ?? baseFontSize ?? kDefaultIconSize;
}
double get iconButtonFactor {
final baseIconFactor = baseButtonExtraOptions?.iconButtonFactor;
final iconButtonFactor = options.iconButtonFactor;
return iconButtonFactor ?? baseIconFactor ?? kDefaultIconButtonFactor;
}
QuillIconTheme? get iconTheme {
return options.iconTheme ?? baseButtonExtraOptions?.iconTheme;
}
QuillToolbarBaseButtonOptions? get baseButtonExtraOptions {
return context.quillToolbarBaseButtonOptions;
}
VoidCallback? get afterButtonPressed {
return options.afterButtonPressed ??
baseButtonExtraOptions?.afterButtonPressed;
}
}
Loading…
Cancel
Save