|
|
@ -458,12 +458,17 @@ class _ImageButtonState extends State<ImageButton> { |
|
|
|
/// buttons for each color. |
|
|
|
/// buttons for each color. |
|
|
|
class ColorButton extends StatefulWidget { |
|
|
|
class ColorButton extends StatefulWidget { |
|
|
|
final IconData icon; |
|
|
|
final IconData icon; |
|
|
|
|
|
|
|
final bool background; |
|
|
|
final QuillController controller; |
|
|
|
final QuillController controller; |
|
|
|
|
|
|
|
|
|
|
|
ColorButton({Key key, @required this.icon, @required this.controller}) |
|
|
|
ColorButton( |
|
|
|
|
|
|
|
{Key key, |
|
|
|
|
|
|
|
@required this.icon, |
|
|
|
|
|
|
|
@required this.controller, |
|
|
|
|
|
|
|
@required this.background}) |
|
|
|
: assert(icon != null), |
|
|
|
: assert(icon != null), |
|
|
|
assert(controller != null), |
|
|
|
assert(controller != null), |
|
|
|
|
|
|
|
assert(background != null), |
|
|
|
super(key: key); |
|
|
|
super(key: key); |
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
@override |
|
|
@ -491,64 +496,9 @@ class _ColorButtonState extends State<ColorButton> { |
|
|
|
if (hex.startsWith('ff')) { |
|
|
|
if (hex.startsWith('ff')) { |
|
|
|
hex = hex.substring(2); |
|
|
|
hex = hex.substring(2); |
|
|
|
} |
|
|
|
} |
|
|
|
widget.controller |
|
|
|
hex = '#$hex'; |
|
|
|
.formatSelection(ColorAttribute('#$hex')); |
|
|
|
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_showColorPicker() { |
|
|
|
|
|
|
|
showDialog( |
|
|
|
|
|
|
|
context: context, |
|
|
|
|
|
|
|
child: AlertDialog( |
|
|
|
|
|
|
|
title: const Text('Select Color'), |
|
|
|
|
|
|
|
content: SingleChildScrollView( |
|
|
|
|
|
|
|
child: MaterialPicker( |
|
|
|
|
|
|
|
pickerColor: Color(0), |
|
|
|
|
|
|
|
onColorChanged: _changeColor, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
)), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Controls background color styles. |
|
|
|
|
|
|
|
/// |
|
|
|
|
|
|
|
/// When pressed, this button displays overlay toolbar with |
|
|
|
|
|
|
|
/// buttons for each color. |
|
|
|
|
|
|
|
class BackgroundColorButton extends StatefulWidget { |
|
|
|
|
|
|
|
final IconData icon; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final QuillController controller; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BackgroundColorButton( |
|
|
|
|
|
|
|
{Key key, @required this.icon, @required this.controller}) |
|
|
|
|
|
|
|
: assert(icon != null), |
|
|
|
|
|
|
|
assert(controller != null), |
|
|
|
|
|
|
|
super(key: key); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
|
|
|
_BackgroundColorButtonState createState() => _BackgroundColorButtonState(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _BackgroundColorButtonState extends State<BackgroundColorButton> { |
|
|
|
|
|
|
|
@override |
|
|
|
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
|
|
|
final theme = Theme.of(context); |
|
|
|
|
|
|
|
final iconColor = theme.iconTheme.color; |
|
|
|
|
|
|
|
final fillColor = theme.canvasColor; |
|
|
|
|
|
|
|
return QuillIconButton( |
|
|
|
|
|
|
|
highlightElevation: 0, |
|
|
|
|
|
|
|
hoverElevation: 0, |
|
|
|
|
|
|
|
size: 32, |
|
|
|
|
|
|
|
icon: Icon(widget.icon, size: 18, color: iconColor), |
|
|
|
|
|
|
|
fillColor: fillColor, |
|
|
|
|
|
|
|
onPressed: _showColorPicker, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _changeColor(Color color) { |
|
|
|
|
|
|
|
widget.controller.formatSelection( |
|
|
|
widget.controller.formatSelection( |
|
|
|
BackgroundAttribute('#${color.value.toRadixString(16)}')); |
|
|
|
widget.background ? BackgroundAttribute(hex) : ColorAttribute(hex)); |
|
|
|
Navigator.of(context).pop(); |
|
|
|
Navigator.of(context).pop(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -643,7 +593,9 @@ class _IndentButtonState extends State<IndentButton> { |
|
|
|
icon: Icon(widget.icon, size: 18, color: iconColor), |
|
|
|
icon: Icon(widget.icon, size: 18, color: iconColor), |
|
|
|
fillColor: fillColor, |
|
|
|
fillColor: fillColor, |
|
|
|
onPressed: () { |
|
|
|
onPressed: () { |
|
|
|
final indent = widget.controller.getSelectionStyle().attributes[Attribute.indent.key]; |
|
|
|
final indent = widget.controller |
|
|
|
|
|
|
|
.getSelectionStyle() |
|
|
|
|
|
|
|
.attributes[Attribute.indent.key]; |
|
|
|
if (indent == null) { |
|
|
|
if (indent == null) { |
|
|
|
if (widget.isIncrease) { |
|
|
|
if (widget.isIncrease) { |
|
|
|
widget.controller.formatSelection(Attribute.indentL1); |
|
|
|
widget.controller.formatSelection(Attribute.indentL1); |
|
|
@ -651,14 +603,17 @@ class _IndentButtonState extends State<IndentButton> { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (indent.value == 1 && !widget.isIncrease) { |
|
|
|
if (indent.value == 1 && !widget.isIncrease) { |
|
|
|
widget.controller.formatSelection(Attribute.clone(Attribute.indentL1, null)); |
|
|
|
widget.controller |
|
|
|
|
|
|
|
.formatSelection(Attribute.clone(Attribute.indentL1, null)); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (widget.isIncrease) { |
|
|
|
if (widget.isIncrease) { |
|
|
|
widget.controller.formatSelection(Attribute.getIndentLevel(indent.value + 1)); |
|
|
|
widget.controller |
|
|
|
|
|
|
|
.formatSelection(Attribute.getIndentLevel(indent.value + 1)); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
widget.controller.formatSelection(Attribute.getIndentLevel(indent.value - 1)); |
|
|
|
widget.controller |
|
|
|
|
|
|
|
.formatSelection(Attribute.getIndentLevel(indent.value - 1)); |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
@ -685,17 +640,17 @@ class _ClearFormatButtonState extends State<ClearFormatButton> { |
|
|
|
final iconColor = theme.iconTheme.color; |
|
|
|
final iconColor = theme.iconTheme.color; |
|
|
|
final fillColor = theme.canvasColor; |
|
|
|
final fillColor = theme.canvasColor; |
|
|
|
return QuillIconButton( |
|
|
|
return QuillIconButton( |
|
|
|
highlightElevation: 0, |
|
|
|
highlightElevation: 0, |
|
|
|
hoverElevation: 0, |
|
|
|
hoverElevation: 0, |
|
|
|
size: 32, |
|
|
|
size: 32, |
|
|
|
icon: Icon(widget.icon, size: 18, color: iconColor), |
|
|
|
icon: Icon(widget.icon, size: 18, color: iconColor), |
|
|
|
fillColor: fillColor, |
|
|
|
fillColor: fillColor, |
|
|
|
onPressed: () { |
|
|
|
onPressed: () { |
|
|
|
for (Attribute k in widget.controller.getSelectionStyle().attributes.values) { |
|
|
|
for (Attribute k |
|
|
|
widget.controller.formatSelection(Attribute.clone(k, null)); |
|
|
|
in widget.controller.getSelectionStyle().attributes.values) { |
|
|
|
} |
|
|
|
widget.controller.formatSelection(Attribute.clone(k, null)); |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -783,14 +738,16 @@ class QuillToolbar extends StatefulWidget implements PreferredSizeWidget { |
|
|
|
child: ColorButton( |
|
|
|
child: ColorButton( |
|
|
|
icon: Icons.format_color_text, |
|
|
|
icon: Icons.format_color_text, |
|
|
|
controller: controller, |
|
|
|
controller: controller, |
|
|
|
|
|
|
|
background: false, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
SizedBox(width: 0.6), |
|
|
|
SizedBox(width: 0.6), |
|
|
|
Visibility( |
|
|
|
Visibility( |
|
|
|
visible: showBackgroundColorButton, |
|
|
|
visible: showBackgroundColorButton, |
|
|
|
child: BackgroundColorButton( |
|
|
|
child: ColorButton( |
|
|
|
icon: Icons.format_color_fill, |
|
|
|
icon: Icons.format_color_fill, |
|
|
|
controller: controller, |
|
|
|
controller: controller, |
|
|
|
|
|
|
|
background: true, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
SizedBox(width: 0.6), |
|
|
|
SizedBox(width: 0.6), |
|
|
|