Refactor code

pull/13/head
singerdmx 4 years ago
parent 8c593a74d2
commit af2cf54b81
  1. 27
      lib/widgets/toolbar.dart

@ -374,19 +374,12 @@ Widget _selectHeadingStyleButtonBuilder(
/// When pressed, this button displays overlay toolbar with /// When pressed, this button displays overlay toolbar with
/// buttons for each color. /// buttons for each color.
class ColorButton extends StatefulWidget { class ColorButton extends StatefulWidget {
final Attribute attribute;
final IconData icon; final IconData icon;
final QuillController controller; final QuillController controller;
ColorButton( ColorButton({Key key, @required this.icon, @required this.controller})
{Key key, : assert(icon != null),
@required this.attribute,
@required this.icon,
@required this.controller})
: assert(attribute.value != null),
assert(icon != null),
assert(controller != null), assert(controller != null),
super(key: key); super(key: key);
@ -395,19 +388,8 @@ class ColorButton extends StatefulWidget {
} }
class _ColorButtonState extends State<ColorButton> { class _ColorButtonState extends State<ColorButton> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return _defaultToggleStyleButtonBuilder(
context, widget.attribute, widget.icon, _showColorPicker);
}
Widget _defaultToggleStyleButtonBuilder(
BuildContext context,
Attribute attribute,
IconData icon,
VoidCallback onPressed,
) {
final theme = Theme.of(context); final theme = Theme.of(context);
final iconColor = theme.iconTheme.color; final iconColor = theme.iconTheme.color;
final fillColor = theme.canvasColor; final fillColor = theme.canvasColor;
@ -415,9 +397,9 @@ class _ColorButtonState extends State<ColorButton> {
highlightElevation: 0, highlightElevation: 0,
hoverElevation: 0, hoverElevation: 0,
size: 32, size: 32,
icon: Icon(icon, size: 18, color: iconColor), icon: Icon(widget.icon, size: 18, color: iconColor),
fillColor: fillColor, fillColor: fillColor,
onPressed: onPressed, onPressed: _showColorPicker,
); );
} }
@ -503,7 +485,6 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget {
Visibility( Visibility(
visible: showColorButton, visible: showColorButton,
child: ColorButton( child: ColorButton(
attribute: ColorAttribute('#000000'),
icon: Icons.format_color_text, icon: Icons.format_color_text,
controller: controller, controller: controller,
), ),

Loading…
Cancel
Save