From 505d7a47fd57b8d549e9fc7eb0eeb94c58525851 Mon Sep 17 00:00:00 2001 From: li3317 Date: Sun, 7 Feb 2021 17:27:32 -0500 Subject: [PATCH] text / background change icon color --- lib/widgets/toolbar.dart | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/widgets/toolbar.dart b/lib/widgets/toolbar.dart index 2d0162d7..0a340470 100644 --- a/lib/widgets/toolbar.dart +++ b/lib/widgets/toolbar.dart @@ -566,6 +566,7 @@ class ColorButton extends StatefulWidget { } class _ColorButtonState extends State { + String colorHex; @override Widget build(BuildContext context) { final theme = Theme.of(context); @@ -575,7 +576,9 @@ class _ColorButtonState extends State { highlightElevation: 0, hoverElevation: 0, size: iconSize * 1.77, - icon: Icon(widget.icon, size: iconSize, color: iconColor), + icon: Icon(widget.icon, + size: iconSize, + color: colorHex == null ? iconColor : fromHex(colorHex)), fillColor: fillColor, onPressed: _showColorPicker, ); @@ -587,11 +590,21 @@ class _ColorButtonState extends State { hex = hex.substring(2); } hex = '#$hex'; + setState(() { + colorHex = hex; + }); widget.controller.formatSelection( widget.background ? BackgroundAttribute(hex) : ColorAttribute(hex)); Navigator.of(context).pop(); } + Color fromHex(String hexString) { + final buffer = StringBuffer(); + if (hexString.length == 6 || hexString.length == 7) buffer.write('ff'); + buffer.write(hexString.replaceFirst('#', '')); + return Color(int.parse(buffer.toString(), radix: 16)); + } + _showColorPicker() { showDialog( context: context,