From 9db3efc3087bc28a2e143f3a74eec22352d10d25 Mon Sep 17 00:00:00 2001 From: Aleksei <130981115+MacDeveloper1@users.noreply.github.com> Date: Tue, 19 Dec 2023 11:53:06 +0100 Subject: [PATCH] Restore correct feel&look of `QuillToolbarIconButton` --- .../toolbar/buttons/quill_icon_button.dart | 54 ++++++++++++------- .../toolbar/buttons/toggle_style_button.dart | 17 ++++-- 2 files changed, 48 insertions(+), 23 deletions(-) diff --git a/lib/src/widgets/toolbar/buttons/quill_icon_button.dart b/lib/src/widgets/toolbar/buttons/quill_icon_button.dart index 22c2fa99..d78494d0 100644 --- a/lib/src/widgets/toolbar/buttons/quill_icon_button.dart +++ b/lib/src/widgets/toolbar/buttons/quill_icon_button.dart @@ -1,40 +1,54 @@ import 'package:flutter/material.dart'; +import '../../../utils/widgets.dart'; + class QuillToolbarIconButton extends StatelessWidget { const QuillToolbarIconButton({ required this.onPressed, - required this.icon, - required this.isFilled, this.afterPressed, + this.icon, + this.size = 40, + this.fillColor, + this.hoverElevation = 1, + this.highlightElevation = 1, + this.borderRadius = 2, this.tooltip, - this.padding, super.key, }); final VoidCallback? onPressed; final VoidCallback? afterPressed; - final Widget icon; + final Widget? icon; + final double size; + final Color? fillColor; + final double hoverElevation; + final double highlightElevation; + final double borderRadius; final String? tooltip; - final EdgeInsets? padding; - final bool isFilled; @override Widget build(BuildContext context) { - if (isFilled) { - return IconButton.filled( - padding: padding, - onPressed: onPressed, - icon: icon, - ); - } - return IconButton( - padding: padding, - onPressed: () { - onPressed?.call(); - afterPressed?.call(); - }, - icon: icon, + return ConstrainedBox( + constraints: BoxConstraints.tightFor(width: size, height: size), + child: UtilityWidgets.maybeTooltip( + message: tooltip, + child: RawMaterialButton( + visualDensity: VisualDensity.compact, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(borderRadius), + ), + fillColor: fillColor, + elevation: 0, + hoverElevation: hoverElevation, + highlightElevation: hoverElevation, + onPressed: () { + onPressed?.call(); + afterPressed?.call(); + }, + child: icon, + ), + ), ); } } diff --git a/lib/src/widgets/toolbar/buttons/toggle_style_button.dart b/lib/src/widgets/toolbar/buttons/toggle_style_button.dart index 6f7f4305..5b64a85a 100644 --- a/lib/src/widgets/toolbar/buttons/toggle_style_button.dart +++ b/lib/src/widgets/toolbar/buttons/toggle_style_button.dart @@ -252,11 +252,22 @@ Widget defaultToggleStyleButtonBuilder( .primaryIconTheme.color) //You can specify your own icon color : (iconTheme?.iconUnselectedColor ?? theme.iconTheme.color) : (iconTheme?.disabledIconColor ?? theme.disabledColor); + final fill = isEnabled + ? isToggled == true + ? (iconTheme?.iconSelectedFillColor ?? + Theme.of(context).primaryColor) //Selected icon fill color + : (iconTheme?.iconUnselectedFillColor ?? + theme.canvasColor) //Unselected icon fill color : + : (iconTheme?.disabledIconFillColor ?? + (fillColor ?? theme.canvasColor)); //Disabled icon fill color return QuillToolbarIconButton( - icon: Icon(icon, size: iconSize * iconButtonFactor, color: iconColor), - isFilled: isEnabled ? isToggled == true : false, + highlightElevation: 0, + hoverElevation: 0, + size: iconSize * iconButtonFactor, + icon: Icon(icon, size: iconSize, color: iconColor), + fillColor: fill, onPressed: onPressed, afterPressed: afterPressed, - padding: iconTheme?.padding, + borderRadius: iconTheme?.borderRadius ?? 2, ); }