From 6932c69716c199aecd4dd46012a8b3a60528d337 Mon Sep 17 00:00:00 2001 From: Ellet Date: Wed, 20 Dec 2023 22:31:51 +0300 Subject: [PATCH] Add a way to change almost properties of IconButton in QuillIconTheme --- example/lib/main.dart | 2 +- .../embeds/image/toolbar/image_button.dart | 3 +- .../others/camera_button/camera_button.dart | 3 +- .../embeds/video/toolbar/video_button.dart | 3 +- lib/src/models/themes/quill_icon_theme.dart | 55 +++++++++++++++++-- .../toolbar/buttons/clear_format_button.dart | 2 +- .../toolbar/buttons/history_button.dart | 3 +- .../toolbar/buttons/indent_button.dart | 3 +- .../toolbar/buttons/quill_icon_button.dart | 48 ++++++++++++---- .../toolbar/buttons/toggle_style_button.dart | 4 +- 10 files changed, 97 insertions(+), 29 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 089042b0..a7ae8990 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -56,7 +56,7 @@ class MyApp extends StatelessWidget { ), ), darkTheme: ThemeData( - useMaterial3: true, + useMaterial3: false, visualDensity: VisualDensity.adaptivePlatformDensity, colorScheme: ColorScheme.fromSeed( brightness: Brightness.dark, diff --git a/flutter_quill_extensions/lib/embeds/image/toolbar/image_button.dart b/flutter_quill_extensions/lib/embeds/image/toolbar/image_button.dart index bd87c22b..aa1be7ad 100644 --- a/flutter_quill_extensions/lib/embeds/image/toolbar/image_button.dart +++ b/flutter_quill_extensions/lib/embeds/image/toolbar/image_button.dart @@ -104,8 +104,7 @@ class QuillToolbarImageButton extends StatelessWidget { tooltip: tooltip, isSelected: false, onPressed: () => _sharedOnPressed(context), - iconSelectedStyle: _iconTheme(context)?.iconButtonSelectedStyle, - iconUnselectedStyle: _iconTheme(context)?.iconButtonUnselectedStyle, + iconTheme: _iconTheme(context), ); } diff --git a/flutter_quill_extensions/lib/embeds/others/camera_button/camera_button.dart b/flutter_quill_extensions/lib/embeds/others/camera_button/camera_button.dart index fb051f28..cbd845fc 100644 --- a/flutter_quill_extensions/lib/embeds/others/camera_button/camera_button.dart +++ b/flutter_quill_extensions/lib/embeds/others/camera_button/camera_button.dart @@ -112,8 +112,7 @@ class QuillToolbarCameraButton extends StatelessWidget { isSelected: false, // isDesktop(supportWeb: false) ? null : onPressed: () => _sharedOnPressed(context), - iconSelectedStyle: iconTheme?.iconButtonSelectedStyle, - iconUnselectedStyle: iconTheme?.iconButtonUnselectedStyle, + iconTheme: _iconTheme(context), ); } diff --git a/flutter_quill_extensions/lib/embeds/video/toolbar/video_button.dart b/flutter_quill_extensions/lib/embeds/video/toolbar/video_button.dart index 323ba5dc..d190406e 100644 --- a/flutter_quill_extensions/lib/embeds/video/toolbar/video_button.dart +++ b/flutter_quill_extensions/lib/embeds/video/toolbar/video_button.dart @@ -109,8 +109,7 @@ class QuillToolbarVideoButton extends StatelessWidget { tooltip: tooltip, isSelected: false, onPressed: () => _sharedOnPressed(context), - iconSelectedStyle: _iconTheme(context)?.iconButtonSelectedStyle, - iconUnselectedStyle: _iconTheme(context)?.iconButtonUnselectedStyle, + iconTheme: _iconTheme(context), ); } diff --git a/lib/src/models/themes/quill_icon_theme.dart b/lib/src/models/themes/quill_icon_theme.dart index bcbc2b6e..e6183319 100644 --- a/lib/src/models/themes/quill_icon_theme.dart +++ b/lib/src/models/themes/quill_icon_theme.dart @@ -6,16 +6,63 @@ class QuillIconTheme { this.padding, this.iconButtonSelectedStyle, this.iconButtonUnselectedStyle, - // this.iconSelectedFillColor, - // this.iconUnselectedFillColor, + this.iconButtonSelectedData, + this.iconButtonUnselectedData, }); + @Deprecated('Please use iconButtonUnselectedData instead') final ButtonStyle? iconButtonUnselectedStyle; + @Deprecated('Please use iconButtonSelectedData instead') final ButtonStyle? iconButtonSelectedStyle; - // final Color? iconSelectedFillColor; - // final Color? iconUnselectedFillColor; + final IconButtonData? iconButtonUnselectedData; + final IconButtonData? iconButtonSelectedData; ///The padding for icons final EdgeInsets? padding; } + +@immutable +class IconButtonData { + const IconButtonData({ + this.iconSize, + this.visualDensity, + this.padding, + this.alignment, + this.splashRadius, + this.color, + this.focusColor, + this.hoverColor, + this.highlightColor, + this.splashColor, + this.disabledColor, + this.mouseCursor, + this.autofocus = false, + this.tooltip, + this.enableFeedback, + this.constraints, + this.style, + this.isSelected, + this.selectedIcon, + }); + + final double? iconSize; + final VisualDensity? visualDensity; + final EdgeInsetsGeometry? padding; + final AlignmentGeometry? alignment; + final double? splashRadius; + final Color? color; + final Color? focusColor; + final Color? hoverColor; + final Color? highlightColor; + final Color? splashColor; + final Color? disabledColor; + final MouseCursor? mouseCursor; + final bool autofocus; + final String? tooltip; + final bool? enableFeedback; + final BoxConstraints? constraints; + final ButtonStyle? style; + final bool? isSelected; + final Widget? selectedIcon; +} diff --git a/lib/src/widgets/toolbar/buttons/clear_format_button.dart b/lib/src/widgets/toolbar/buttons/clear_format_button.dart index e718cd8e..41df3834 100644 --- a/lib/src/widgets/toolbar/buttons/clear_format_button.dart +++ b/lib/src/widgets/toolbar/buttons/clear_format_button.dart @@ -114,7 +114,7 @@ class QuillToolbarClearFormatButton extends StatelessWidget { isSelected: false, onPressed: _sharedOnPressed, afterPressed: afterButtonPressed, - iconUnselectedStyle: iconTheme?.iconButtonUnselectedStyle, + iconTheme: iconTheme, ); } } diff --git a/lib/src/widgets/toolbar/buttons/history_button.dart b/lib/src/widgets/toolbar/buttons/history_button.dart index 21271a7f..0527c3fa 100644 --- a/lib/src/widgets/toolbar/buttons/history_button.dart +++ b/lib/src/widgets/toolbar/buttons/history_button.dart @@ -104,8 +104,7 @@ class QuillToolbarHistoryButtonState extends State { size: iconSize * iconButtonFactor, ), isSelected: false, - iconSelectedStyle: iconTheme?.iconButtonSelectedStyle, - iconUnselectedStyle: iconTheme?.iconButtonUnselectedStyle, + iconTheme: iconTheme, onPressed: _canPressed ? _updateHistory : null, afterPressed: afterButtonPressed, ); diff --git a/lib/src/widgets/toolbar/buttons/indent_button.dart b/lib/src/widgets/toolbar/buttons/indent_button.dart index 6778f790..2c96de42 100644 --- a/lib/src/widgets/toolbar/buttons/indent_button.dart +++ b/lib/src/widgets/toolbar/buttons/indent_button.dart @@ -116,8 +116,7 @@ class QuillToolbarIndentButtonState extends State { isSelected: false, onPressed: _sharedOnPressed, afterPressed: afterButtonPressed, - iconSelectedStyle: iconTheme?.iconButtonSelectedStyle, - iconUnselectedStyle: iconTheme?.iconButtonUnselectedStyle, + iconTheme: iconTheme, ); } } diff --git a/lib/src/widgets/toolbar/buttons/quill_icon_button.dart b/lib/src/widgets/toolbar/buttons/quill_icon_button.dart index a21e4c7a..e3350d1b 100644 --- a/lib/src/widgets/toolbar/buttons/quill_icon_button.dart +++ b/lib/src/widgets/toolbar/buttons/quill_icon_button.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; +import '../../../models/themes/quill_icon_theme.dart'; + class QuillToolbarIconButton extends StatelessWidget { const QuillToolbarIconButton({ required this.onPressed, @@ -7,10 +9,8 @@ class QuillToolbarIconButton extends StatelessWidget { required this.isSelected, this.afterPressed, this.tooltip, - this.padding, super.key, - this.iconSelectedStyle, - this.iconUnselectedStyle, + this.iconTheme, }); final VoidCallback? onPressed; @@ -18,25 +18,37 @@ class QuillToolbarIconButton extends StatelessWidget { final Widget icon; final String? tooltip; - final EdgeInsets? padding; final bool isSelected; - final ButtonStyle? iconUnselectedStyle; - final ButtonStyle? iconSelectedStyle; + final QuillIconTheme? iconTheme; @override Widget build(BuildContext context) { if (isSelected) { return IconButton.filled( tooltip: tooltip, - padding: padding, onPressed: onPressed, icon: icon, - style: iconSelectedStyle, + style: iconTheme?.iconButtonSelectedData?.style, + visualDensity: iconTheme?.iconButtonSelectedData?.visualDensity, + iconSize: iconTheme?.iconButtonSelectedData?.iconSize, + padding: iconTheme?.iconButtonSelectedData?.padding, + alignment: iconTheme?.iconButtonSelectedData?.alignment, + splashRadius: iconTheme?.iconButtonSelectedData?.splashRadius, + color: iconTheme?.iconButtonSelectedData?.color, + focusColor: iconTheme?.iconButtonSelectedData?.focusColor, + hoverColor: iconTheme?.iconButtonSelectedData?.hoverColor, + highlightColor: iconTheme?.iconButtonSelectedData?.highlightColor, + splashColor: iconTheme?.iconButtonSelectedData?.splashColor, + disabledColor: iconTheme?.iconButtonSelectedData?.disabledColor, + mouseCursor: iconTheme?.iconButtonSelectedData?.mouseCursor, + autofocus: iconTheme?.iconButtonSelectedData?.autofocus ?? false, + enableFeedback: iconTheme?.iconButtonSelectedData?.enableFeedback, + constraints: iconTheme?.iconButtonSelectedData?.constraints, + selectedIcon: iconTheme?.iconButtonSelectedData?.selectedIcon, ); } return IconButton( tooltip: tooltip, - padding: padding, onPressed: onPressed != null ? () { onPressed?.call(); @@ -44,7 +56,23 @@ class QuillToolbarIconButton extends StatelessWidget { } : null, icon: icon, - style: iconUnselectedStyle, + style: iconTheme?.iconButtonUnselectedData?.style, + visualDensity: iconTheme?.iconButtonUnselectedData?.visualDensity, + iconSize: iconTheme?.iconButtonUnselectedData?.iconSize, + padding: iconTheme?.iconButtonUnselectedData?.padding, + alignment: iconTheme?.iconButtonUnselectedData?.alignment, + splashRadius: iconTheme?.iconButtonUnselectedData?.splashRadius, + color: iconTheme?.iconButtonUnselectedData?.color, + focusColor: iconTheme?.iconButtonUnselectedData?.focusColor, + hoverColor: iconTheme?.iconButtonUnselectedData?.hoverColor, + highlightColor: iconTheme?.iconButtonUnselectedData?.highlightColor, + splashColor: iconTheme?.iconButtonUnselectedData?.splashColor, + disabledColor: iconTheme?.iconButtonUnselectedData?.disabledColor, + mouseCursor: iconTheme?.iconButtonUnselectedData?.mouseCursor, + autofocus: iconTheme?.iconButtonUnselectedData?.autofocus ?? false, + enableFeedback: iconTheme?.iconButtonUnselectedData?.enableFeedback, + constraints: iconTheme?.iconButtonUnselectedData?.constraints, + selectedIcon: iconTheme?.iconButtonUnselectedData?.selectedIcon, ); } } diff --git a/lib/src/widgets/toolbar/buttons/toggle_style_button.dart b/lib/src/widgets/toolbar/buttons/toggle_style_button.dart index 41c503fd..46408b94 100644 --- a/lib/src/widgets/toolbar/buttons/toggle_style_button.dart +++ b/lib/src/widgets/toolbar/buttons/toggle_style_button.dart @@ -256,8 +256,6 @@ Widget defaultToggleStyleButtonBuilder( isSelected: isEnabled ? isToggled == true : false, onPressed: onPressed, afterPressed: afterPressed, - padding: iconTheme?.padding, - iconUnselectedStyle: iconTheme?.iconButtonUnselectedStyle, - iconSelectedStyle: iconTheme?.iconButtonSelectedStyle, + iconTheme: iconTheme, ); }