From 1df66a8b737b1ce9fb1d50c18b25e4bc44a54314 Mon Sep 17 00:00:00 2001 From: Ellet Date: Mon, 13 Nov 2023 06:43:44 +0300 Subject: [PATCH] feat: allow to use custom callback QuillToolbarColorButton --- CHANGELOG.md | 4 ++ .../models/config/toolbar/buttons/color.dart | 12 ++++- .../models/config/toolbar/buttons/search.dart | 4 +- .../widgets/toolbar/buttons/color/color.dart | 18 +++++++- .../toolbar/buttons/search/search.dart | 46 ------------------- .../toolbar/buttons/select_header_style.dart | 2 - 6 files changed, 32 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ef722c6..0b4e458f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [8.5.2] +- Update `README.md` +- Feature: Allow you to add custom callback when the `QuillToolbarColorButton` pressed + ## [8.5.1] - Update `README.md` diff --git a/lib/src/models/config/toolbar/buttons/color.dart b/lib/src/models/config/toolbar/buttons/color.dart index bff832e8..e6c2f9c5 100644 --- a/lib/src/models/config/toolbar/buttons/color.dart +++ b/lib/src/models/config/toolbar/buttons/color.dart @@ -1,6 +1,7 @@ import 'package:flutter/widgets.dart' show Color; -import './../../shared_configurations.dart' show QuillSharedConfigurations; +import './../../shared_configurations.dart' show QuillSharedConfigurations; +import '../../../../widgets/controller.dart'; import 'base.dart'; class QuillToolbarColorButtonExtraOptions @@ -31,9 +32,9 @@ class QuillToolbarColorButtonOptions extends QuillToolbarBaseButtonOptions< super.afterButtonPressed, super.childBuilder, super.controller, - super.globalIconSize, super.iconTheme, super.tooltip, + this.customOnPressedCallback, }); final double? iconSize; @@ -42,4 +43,11 @@ class QuillToolbarColorButtonOptions extends QuillToolbarBaseButtonOptions< /// By default will use the default `dialogBarrierColor` from /// [QuillSharedConfigurations] final Color? dialogBarrierColor; + + final QuillToolbarColorPickerOnPressedCallback? customOnPressedCallback; } + +typedef QuillToolbarColorPickerOnPressedCallback = Future Function( + QuillController controller, + bool isBackground, +); diff --git a/lib/src/models/config/toolbar/buttons/search.dart b/lib/src/models/config/toolbar/buttons/search.dart index 6ba95f07..6d18fad2 100644 --- a/lib/src/models/config/toolbar/buttons/search.dart +++ b/lib/src/models/config/toolbar/buttons/search.dart @@ -38,10 +38,10 @@ class QuillToolbarSearchButtonOptions extends QuillToolbarBaseButtonOptions { /// By default we will show simple search dialog ui /// you can pass value to this callback to change this - final QuillToolbarSearchButtomOnPressedCallback? customOnPressedCallback; + final QuillToolbarSearchButtonOnPressedCallback? customOnPressedCallback; } -typedef QuillToolbarSearchButtomOnPressedCallback = Future Function( +typedef QuillToolbarSearchButtonOnPressedCallback = Future Function( QuillController controller, ); diff --git a/lib/src/widgets/toolbar/buttons/color/color.dart b/lib/src/widgets/toolbar/buttons/color/color.dart index f6af8737..2986dfb5 100644 --- a/lib/src/widgets/toolbar/buttons/color/color.dart +++ b/lib/src/widgets/toolbar/buttons/color/color.dart @@ -167,7 +167,16 @@ class QuillToolbarColorButtonState extends State { // if the caller using Cupertino app he might need to wrap the builder // with Material() widget return childBuilder( - options, + QuillToolbarColorButtonOptions( + afterButtonPressed: afterButtonPressed, + dialogBarrierColor: options.dialogBarrierColor, + tooltip: tooltip, + iconTheme: iconTheme, + iconSize: iconSize, + iconData: iconData, + iconButtonFactor: iconButtonFactor, + customOnPressedCallback: options.customOnPressedCallback, + ), QuillToolbarColorButtonExtraOptions( controller: controller, context: context, @@ -206,7 +215,12 @@ class QuillToolbarColorButtonState extends State { ); } - void _showColorPicker() { + Future _showColorPicker() async { + final customCallback = options.customOnPressedCallback; + if (customCallback != null) { + await customCallback(controller, widget.isBackground); + return; + } showDialog( context: context, barrierColor: options.dialogBarrierColor ?? diff --git a/lib/src/widgets/toolbar/buttons/search/search.dart b/lib/src/widgets/toolbar/buttons/search/search.dart index 676bc71a..ceacdf8a 100644 --- a/lib/src/widgets/toolbar/buttons/search/search.dart +++ b/lib/src/widgets/toolbar/buttons/search/search.dart @@ -147,50 +147,4 @@ class QuillToolbarSearchButton extends StatelessWidget { ), ); } - - // Those functions ((findText, moveToPosition)) are not ready yet. - // but consider moving them to a better place - // List _findText({ - // required int index, - // required String text, - // required QuillController controller, - // required List offsets, - // required bool wholeWord, - // required bool caseSensitive, - // bool moveToPosition = true, - // }) { - // if (text.isEmpty) { - // return List.empty(); - // } - // final newOffsets = controller.document.search( - // text, - // caseSensitive: caseSensitive, - // wholeWord: wholeWord, - // ); - // index = 0; // TODO: This might need to be updated... - // if (offsets.isNotEmpty && moveToPosition) { - // _moveToPosition( - // index: index, - // text: text, - // controller: controller, - // offsets: offsets, - // ); - // } - // return newOffsets; - // } - - // void _moveToPosition({ - // required int index, - // required String text, - // required QuillController controller, - // required List offsets, - // }) { - // controller.updateSelection( - // TextSelection( - // baseOffset: offsets[index], - // extentOffset: offsets[index] + text.length, - // ), - // ChangeSource.LOCAL, - // ); - // } } diff --git a/lib/src/widgets/toolbar/buttons/select_header_style.dart b/lib/src/widgets/toolbar/buttons/select_header_style.dart index c2cbc5ca..15e02dab 100644 --- a/lib/src/widgets/toolbar/buttons/select_header_style.dart +++ b/lib/src/widgets/toolbar/buttons/select_header_style.dart @@ -145,8 +145,6 @@ class QuillToolbarSelectHeaderStyleButtonsState } final theme = Theme.of(context); final isSelected = _selectedAttribute == attribute; - // TODO: This needs to be updated to materail 3 as well just like in - // quill_icon.dart return Padding( padding: const EdgeInsets.symmetric(horizontal: !kIsWeb ? 1.0 : 5.0), child: ConstrainedBox(