From 93d77cf08aaa8ff23f4e2f2aa462ce696c3e4935 Mon Sep 17 00:00:00 2001 From: Aleksei <130981115+MacDeveloper1@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:01:03 +0100 Subject: [PATCH] Restore old feel & look with supprt Material 3 --- .../toolbar/buttons/quill_icon_button.dart | 64 ++++++++++++++----- 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/lib/src/widgets/toolbar/buttons/quill_icon_button.dart b/lib/src/widgets/toolbar/buttons/quill_icon_button.dart index 3024133b..af57d8dc 100644 --- a/lib/src/widgets/toolbar/buttons/quill_icon_button.dart +++ b/lib/src/widgets/toolbar/buttons/quill_icon_button.dart @@ -1,5 +1,8 @@ import 'package:flutter/material.dart'; +import '../../../../extensions.dart'; +import '../../../../flutter_quill.dart'; + class QuillToolbarIconButton extends StatelessWidget { const QuillToolbarIconButton({ required this.onPressed, @@ -11,6 +14,8 @@ class QuillToolbarIconButton extends StatelessWidget { super.key, this.iconFilledStyle, this.iconStyle, + this.size = 40, + this.iconTheme, }); final VoidCallback? onPressed; @@ -20,27 +25,56 @@ class QuillToolbarIconButton extends StatelessWidget { final String? tooltip; final EdgeInsets? padding; final bool isFilled; - final ButtonStyle? iconStyle; final ButtonStyle? iconFilledStyle; + final QuillIconTheme? iconTheme; + + /// Container size. + final double size; + @override Widget build(BuildContext context) { - if (isFilled) { - return IconButton.filled( - padding: padding, - onPressed: onPressed, - icon: icon, - style: iconStyle, + final theme = Theme.of(context); + Widget child; + if (theme.useMaterial3) { + child = isFilled + ? IconButton.filled( + padding: padding, + icon: icon, + style: iconFilledStyle, + onPressed: _onPressed, + ) + : IconButton( + padding: padding, + icon: icon, + style: iconStyle, + onPressed: _onPressed, + ); + } else { + child = UtilityWidgets.maybeTooltip( + message: tooltip, + child: RawMaterialButton( + visualDensity: VisualDensity.compact, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(iconTheme?.borderRadius ?? 2), + ), + fillColor: iconFilledStyle?.backgroundColor?.resolve({}), + elevation: 0, + hoverElevation: 0, + highlightElevation: 0, + onPressed: _onPressed, + child: icon, + ), ); } - return IconButton( - padding: padding, - onPressed: () { - onPressed?.call(); - afterPressed?.call(); - }, - icon: icon, - style: iconFilledStyle, + return ConstrainedBox( + constraints: BoxConstraints.tightFor(width: size, height: size), + child: child, ); } + + void _onPressed() { + onPressed?.call(); + afterPressed?.call(); + } }