From aabd9f2fa5e279ea51f4769e9f0914c2238881c0 Mon Sep 17 00:00:00 2001 From: Ellet Date: Sat, 2 Dec 2023 08:25:47 +0300 Subject: [PATCH] docs: Update the custom toolbar example --- .../lib/presentation/quill/quill_toolbar.dart | 28 +++++++++++++------ .../models/config/toolbar/buttons/base.dart | 20 ------------- .../config/toolbar/buttons/toggle_style.dart | 1 + .../widgets/toolbar/buttons/toggle_style.dart | 11 +++++++- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/example/lib/presentation/quill/quill_toolbar.dart b/example/lib/presentation/quill/quill_toolbar.dart index 4ce92d9e0..f7aedf2af 100644 --- a/example/lib/presentation/quill/quill_toolbar.dart +++ b/example/lib/presentation/quill/quill_toolbar.dart @@ -102,6 +102,11 @@ class MyQuillToolbar extends StatelessWidget { configurations: QuillBaseToolbarConfigurations( toolbarSize: 15 * 2, multiRowsDisplay: false, + buttonOptions: const QuillToolbarButtonOptions( + base: QuillToolbarBaseButtonOptions( + globalIconSize: 30, + ), + ), childrenBuilder: (context) { final controller = context.requireQuillController; return [ @@ -122,9 +127,19 @@ class MyQuillToolbar extends StatelessWidget { QuillToolbarToggleStyleButton( attribute: Attribute.bold, controller: controller, - options: const QuillToolbarToggleStyleButtonOptions( - iconData: Icons.format_bold, - iconSize: 20, + options: QuillToolbarToggleStyleButtonOptions( + childBuilder: (options, extraOptions) { + if (extraOptions.isToggled) { + return IconButton.filled( + onPressed: extraOptions.onPressed, + icon: Icon(options.iconData), + ); + } + return IconButton( + onPressed: extraOptions.onPressed, + icon: Icon(options.iconData), + ); + }, ), ), QuillToolbarToggleStyleButton( @@ -132,7 +147,6 @@ class MyQuillToolbar extends StatelessWidget { controller: controller, options: const QuillToolbarToggleStyleButtonOptions( iconData: Icons.format_italic, - iconSize: 20, ), ), QuillToolbarToggleStyleButton( @@ -147,7 +161,6 @@ class MyQuillToolbar extends StatelessWidget { controller: controller, options: const QuillToolbarClearFormatButtonOptions( iconData: Icons.format_clear, - iconSize: 20, ), ), VerticalDivider( @@ -166,7 +179,7 @@ class MyQuillToolbar extends StatelessWidget { controller: controller, options: const QuillToolbarToggleStyleButtonOptions( iconData: Icons.format_list_numbered, - iconSize: 20, + iconSize: 39, ), ), QuillToolbarToggleStyleButton( @@ -174,7 +187,6 @@ class MyQuillToolbar extends StatelessWidget { controller: controller, options: const QuillToolbarToggleStyleButtonOptions( iconData: Icons.format_list_bulleted, - iconSize: 20, ), ), QuillToolbarToggleStyleButton( @@ -182,7 +194,7 @@ class MyQuillToolbar extends StatelessWidget { controller: controller, options: const QuillToolbarToggleStyleButtonOptions( iconData: Icons.format_quote, - iconSize: 20, + iconSize: 15, ), ), VerticalDivider( diff --git a/lib/src/models/config/toolbar/buttons/base.dart b/lib/src/models/config/toolbar/buttons/base.dart index 2eadbff8d..22ed54b29 100644 --- a/lib/src/models/config/toolbar/buttons/base.dart +++ b/lib/src/models/config/toolbar/buttons/base.dart @@ -90,26 +90,6 @@ class QuillToolbarBaseButtonOptions extends Equatable { childBuilder, controller, ]; - - // QuillToolbarBaseButtonOptions copyWith({ - // IconData? iconData, - // double? globalIconSize, - // VoidCallback? afterButtonPressed, - // String? tooltip, - // QuillIconTheme? iconTheme, - // Widget Function(T options, I extraOptions)? childBuilder, - // QuillController? controller, - // }) { - // return QuillToolbarBaseButtonOptions( - // iconData: iconData ?? this.iconData, - // globalIconSize: globalIconSize ?? this.globalIconSize, - // afterButtonPressed: afterButtonPressed ?? this.afterButtonPressed, - // tooltip: tooltip ?? this.tooltip, - // iconTheme: iconTheme ?? this.iconTheme, - // childBuilder: childBuilder ?? this.childBuilder, - // controller: controller ?? this.controller, - // ); - // } } typedef QuillToolbarButtonOptionsChildBuilder = Widget Function( diff --git a/lib/src/models/config/toolbar/buttons/toggle_style.dart b/lib/src/models/config/toolbar/buttons/toggle_style.dart index 2c2ef1dd7..97af1319f 100644 --- a/lib/src/models/config/toolbar/buttons/toggle_style.dart +++ b/lib/src/models/config/toolbar/buttons/toggle_style.dart @@ -1,3 +1,4 @@ +// ignore_for_file: public_member_api_docs, sort_constructors_first import 'package:flutter/foundation.dart' show immutable; import 'package:flutter/widgets.dart' show Color; diff --git a/lib/src/widgets/toolbar/buttons/toggle_style.dart b/lib/src/widgets/toolbar/buttons/toggle_style.dart index 7ac767986..dabf225e0 100644 --- a/lib/src/widgets/toolbar/buttons/toggle_style.dart +++ b/lib/src/widgets/toolbar/buttons/toggle_style.dart @@ -146,7 +146,16 @@ class QuillToolbarToggleStyleButtonState context.requireQuillToolbarBaseButtonOptions.childBuilder; if (childBuilder != null) { return childBuilder( - options, + QuillToolbarToggleStyleButtonOptions( + afterButtonPressed: options.afterButtonPressed, + controller: controller, + fillColor: options.fillColor, + iconButtonFactor: options.iconButtonFactor, + iconData: iconData, + iconSize: iconSize, + tooltip: tooltip, + iconTheme: iconTheme, + ), QuillToolbarToggleStyleButtonExtraOptions( context: context, controller: controller,