From 16aa851c043ea5a4b7ee7cf7a521c22a4235aa34 Mon Sep 17 00:00:00 2001 From: Ahmed Hnewa <73608287+freshtechtips@users.noreply.github.com> Date: Tue, 24 Oct 2023 23:09:01 +0300 Subject: [PATCH] Little adjusments && Update CHANGELOG.md --- CHANGELOG.md | 2 ++ lib/src/widgets/editor/editor.dart | 1 - .../widgets/toolbar/buttons/clear_format.dart | 8 +++-- lib/src/widgets/toolbar/buttons/color.dart | 4 ++- .../toolbar/buttons/custom_button.dart | 4 +-- .../widgets/toolbar/buttons/font_size.dart | 1 - lib/src/widgets/toolbar/buttons/history.dart | 8 ++--- lib/src/widgets/toolbar/buttons/indent.dart | 30 +++++++++++++++++-- .../widgets/toolbar/buttons/link_style.dart | 11 +------ .../toolbar/buttons/search/search.dart | 12 ++++---- .../toolbar/buttons/select_alignment.dart | 4 +-- .../toolbar/buttons/select_header_style.dart | 2 +- .../widgets/toolbar/buttons/toggle_style.dart | 24 --------------- lib/src/widgets/toolbar/toolbar.dart | 1 - 14 files changed, 53 insertions(+), 59 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b931907..912276a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## [7.10.1] - Fixes and use the new parameters +- You don't need to use MaterialApp to use most of the toolbar buttons childBuilder anymore +- Compatibility with [fresh_quill_extensions](https://pub.dev/packages/fresh_quill_extensions) which is temporary alternative to [flutter_quill_extensions](https://pub.dev/packages/flutter_quill_extensions) ## [7.10.0] - **Breaking change**: `QuillToolbar.basic()` can be accessed from `QuillToolbar()` directly and the old `QuillToolbar` can be accessed from `QuillBaseToolbar` diff --git a/lib/src/widgets/editor/editor.dart b/lib/src/widgets/editor/editor.dart index 042b0d85..bc11b35e 100644 --- a/lib/src/widgets/editor/editor.dart +++ b/lib/src/widgets/editor/editor.dart @@ -15,7 +15,6 @@ import 'package:i18n_extension/i18n_widget.dart'; import '../../../flutter_quill.dart'; import '../../models/documents/nodes/container.dart' as container_node; -import '../../utils/extensions/build_context.dart'; import '../../utils/platform.dart'; import '../box.dart'; import '../cursor.dart'; diff --git a/lib/src/widgets/toolbar/buttons/clear_format.dart b/lib/src/widgets/toolbar/buttons/clear_format.dart index aabf5576..2e2c4e9d 100644 --- a/lib/src/widgets/toolbar/buttons/clear_format.dart +++ b/lib/src/widgets/toolbar/buttons/clear_format.dart @@ -66,10 +66,7 @@ class QuillToolbarClearFormatButton extends StatelessWidget { @override Widget build(BuildContext context) { - final theme = Theme.of(context); final iconTheme = _iconTheme(context); - final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color; - final fillColor = iconTheme?.iconUnselectedFillColor ?? theme.canvasColor; final tooltip = _tooltip(context); final iconSize = _iconSize(context); final iconData = _iconData(context); @@ -99,6 +96,11 @@ class QuillToolbarClearFormatButton extends StatelessWidget { ); } + final theme = Theme.of(context); + + final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color; + final fillColor = iconTheme?.iconUnselectedFillColor ?? theme.canvasColor; + return QuillToolbarIconButton( tooltip: tooltip, highlightElevation: 0, diff --git a/lib/src/widgets/toolbar/buttons/color.dart b/lib/src/widgets/toolbar/buttons/color.dart index fd5ae817..ed431fea 100644 --- a/lib/src/widgets/toolbar/buttons/color.dart +++ b/lib/src/widgets/toolbar/buttons/color.dart @@ -157,6 +157,8 @@ class _QuillToolbarColorButtonState extends State { final childBuilder = options.childBuilder ?? baseButtonExtraOptions.childBuilder; if (childBuilder != null) { + // if the caller using Cupertino app he might need to wrap the builder + // with Material() widget return childBuilder( options, QuillToolbarColorButtonExtraOptions( @@ -166,7 +168,7 @@ class _QuillToolbarColorButtonState extends State { _showColorPicker(); afterButtonPressed?.call(); }, - iconColor: iconColor, + iconColor: null, iconColorBackground: iconColorBackground, fillColor: fillColor, fillColorBackground: fillColorBackground, diff --git a/lib/src/widgets/toolbar/buttons/custom_button.dart b/lib/src/widgets/toolbar/buttons/custom_button.dart index 14911446..50745e74 100644 --- a/lib/src/widgets/toolbar/buttons/custom_button.dart +++ b/lib/src/widgets/toolbar/buttons/custom_button.dart @@ -12,8 +12,8 @@ class CustomButton extends StatelessWidget { this.iconTheme, this.afterButtonPressed, this.tooltip, - Key? key, - }) : super(key: key); + super.key, + }); final VoidCallback? onPressed; final IconData? icon; diff --git a/lib/src/widgets/toolbar/buttons/font_size.dart b/lib/src/widgets/toolbar/buttons/font_size.dart index 5eebe463..419ad46a 100644 --- a/lib/src/widgets/toolbar/buttons/font_size.dart +++ b/lib/src/widgets/toolbar/buttons/font_size.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import '../../../../extensions.dart'; import '../../../../flutter_quill.dart'; import '../../../translations/toolbar.i18n.dart'; -import '../../../utils/extensions/build_context.dart'; import '../../../utils/font.dart'; class QuillToolbarFontSizeButton extends StatefulWidget { diff --git a/lib/src/widgets/toolbar/buttons/history.dart b/lib/src/widgets/toolbar/buttons/history.dart index 2098eb52..297b4b9f 100644 --- a/lib/src/widgets/toolbar/buttons/history.dart +++ b/lib/src/widgets/toolbar/buttons/history.dart @@ -49,8 +49,6 @@ class _QuillToolbarHistoryButtonState extends State { @override Widget build(BuildContext context) { - theme = Theme.of(context); - final baseButtonConfigurations = context.requireQuillToolbarBaseButtonOptions; final tooltip = options.tooltip ?? @@ -65,8 +63,6 @@ class _QuillToolbarHistoryButtonState extends State { context.requireQuillToolbarBaseButtonOptions.globalIconSize; final iconTheme = options.iconTheme ?? baseButtonConfigurations.iconTheme; - final fillColor = iconTheme?.iconUnselectedFillColor ?? theme.canvasColor; - final afterButtonPressed = options.afterButtonPressed ?? baseButtonConfigurations.afterButtonPressed; @@ -92,6 +88,10 @@ class _QuillToolbarHistoryButtonState extends State { ), ); } + + theme = Theme.of(context); + + final fillColor = iconTheme?.iconUnselectedFillColor ?? theme.canvasColor; return QuillToolbarIconButton( tooltip: tooltip, highlightElevation: 0, diff --git a/lib/src/widgets/toolbar/buttons/indent.dart b/lib/src/widgets/toolbar/buttons/indent.dart index 0ce83764..8aad9671 100644 --- a/lib/src/widgets/toolbar/buttons/indent.dart +++ b/lib/src/widgets/toolbar/buttons/indent.dart @@ -70,8 +70,34 @@ class _QuillToolbarIndentButtonState extends State { (widget.isIncrease ? 'Increase indent'.i18n : 'Decrease indent'.i18n); } + void _sharedOnPressed() { + widget.controller.indentSelection(widget.isIncrease); + } + @override Widget build(BuildContext context) { + final childBuilder = + options.childBuilder ?? baseButtonExtraOptions.childBuilder; + + if (childBuilder != null) { + return childBuilder( + QuillToolbarIndentButtonOptions( + afterButtonPressed: afterButtonPressed, + iconData: iconData, + iconSize: iconSize, + iconTheme: iconTheme, + tooltip: tooltip, + ), + QuillToolbarIndentButtonExtraOptions( + controller: controller, + context: context, + onPressed: () { + _sharedOnPressed(); + afterButtonPressed?.call(); + }, + ), + ); + } final theme = Theme.of(context); final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color; @@ -85,9 +111,7 @@ class _QuillToolbarIndentButtonState extends State { icon: Icon(iconData, size: iconSize, color: iconColor), fillColor: iconFillColor, borderRadius: iconTheme?.borderRadius ?? 2, - onPressed: () { - widget.controller.indentSelection(widget.isIncrease); - }, + onPressed: _sharedOnPressed, afterPressed: afterButtonPressed, ); } diff --git a/lib/src/widgets/toolbar/buttons/link_style.dart b/lib/src/widgets/toolbar/buttons/link_style.dart index 2188aeff..15cd5af1 100644 --- a/lib/src/widgets/toolbar/buttons/link_style.dart +++ b/lib/src/widgets/toolbar/buttons/link_style.dart @@ -19,15 +19,6 @@ class QuillToolbarLinkStyleButton extends StatefulWidget { }); final QuillController controller; - // final IconData? icon; - // final double iconSize; - // final QuillIconTheme? iconTheme; - // final QuillDialogTheme? dialogTheme; - // final VoidCallback? afterButtonPressed; - // final String? tooltip; - // final RegExp? linkRegExp; - // final LinkDialogAction? linkDialogAction; - // final Color dialogBarrierColor; final QuillToolbarLinkStyleButtonOptions options; @override @@ -110,7 +101,6 @@ class _QuillToolbarLinkStyleButtonState @override Widget build(BuildContext context) { - final theme = Theme.of(context); final isToggled = _getLinkAttributeValue() != null; final pressedHandler = () => _openLinkDialog(context); @@ -140,6 +130,7 @@ class _QuillToolbarLinkStyleButtonState ), ); } + final theme = Theme.of(context); return QuillToolbarIconButton( tooltip: tooltip, highlightElevation: 0, diff --git a/lib/src/widgets/toolbar/buttons/search/search.dart b/lib/src/widgets/toolbar/buttons/search/search.dart index 6773aab5..0f8537f0 100644 --- a/lib/src/widgets/toolbar/buttons/search/search.dart +++ b/lib/src/widgets/toolbar/buttons/search/search.dart @@ -64,18 +64,12 @@ class QuillToolbarSearchButton extends StatelessWidget { @override Widget build(BuildContext context) { - final theme = Theme.of(context); - final iconTheme = _iconTheme(context); final tooltip = _tooltip(context); final iconData = _iconData(context); final iconSize = _iconSize(context); final afterButtonPressed = _afterButtonPressed(context); - final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color; - final iconFillColor = iconTheme?.iconUnselectedFillColor ?? - (options.fillColor ?? theme.canvasColor); - final childBuilder = options.childBuilder ?? baseButtonExtraOptions(context).childBuilder; @@ -103,6 +97,12 @@ class QuillToolbarSearchButton extends StatelessWidget { ); } + final theme = Theme.of(context); + + final iconColor = iconTheme?.iconUnselectedColor ?? theme.iconTheme.color; + final iconFillColor = iconTheme?.iconUnselectedFillColor ?? + (options.fillColor ?? theme.canvasColor); + return QuillToolbarIconButton( tooltip: tooltip, icon: Icon( diff --git a/lib/src/widgets/toolbar/buttons/select_alignment.dart b/lib/src/widgets/toolbar/buttons/select_alignment.dart index 03bccd82..2d4018dd 100644 --- a/lib/src/widgets/toolbar/buttons/select_alignment.dart +++ b/lib/src/widgets/toolbar/buttons/select_alignment.dart @@ -183,8 +183,6 @@ class _QuillToolbarSelectAlignmentButtonState // Attribute.justifyAlignment: ToolbarButtons.justifyAlignment, // }; - final theme = Theme.of(context); - final buttonCount = ((widget.showLeftAlignment!) ? 1 : 0) + ((widget.showCenterAlignment!) ? 1 : 0) + ((widget.showRightAlignment!) ? 1 : 0) + @@ -200,6 +198,8 @@ class _QuillToolbarSelectAlignmentButtonState ); } + final theme = Theme.of(context); + return Row( mainAxisSize: MainAxisSize.min, children: List.generate(buttonCount, (index) { diff --git a/lib/src/widgets/toolbar/buttons/select_header_style.dart b/lib/src/widgets/toolbar/buttons/select_header_style.dart index 7b840e11..57ba28d2 100644 --- a/lib/src/widgets/toolbar/buttons/select_header_style.dart +++ b/lib/src/widgets/toolbar/buttons/select_header_style.dart @@ -99,7 +99,6 @@ class _QuillToolbarSelectHeaderStyleButtonsState 'All attributes must be one of them: header, h1, h2 or h3', ); - final theme = Theme.of(context); final style = TextStyle( fontWeight: FontWeight.w600, fontSize: iconSize * 0.7, @@ -114,6 +113,7 @@ class _QuillToolbarSelectHeaderStyleButtonsState ' is not supported. Yet but we will work on that soon.', ); } + final theme = Theme.of(context); final children = options.attributes.map((attribute) { final isSelected = _selectedAttribute == attribute; diff --git a/lib/src/widgets/toolbar/buttons/toggle_style.dart b/lib/src/widgets/toolbar/buttons/toggle_style.dart index fa351292..38b8bc6b 100644 --- a/lib/src/widgets/toolbar/buttons/toggle_style.dart +++ b/lib/src/widgets/toolbar/buttons/toggle_style.dart @@ -26,37 +26,13 @@ class QuillToolbarToggleStyleButton extends StatefulWidget { required this.options, required this.controller, required this.attribute, - // required this.icon, - // required this.controller, - // this.iconSize = kDefaultIconSize, - // this.fillColor, - // this.childBuilder = defaultToggleStyleButtonBuilder, - // this.iconTheme, - // this.afterButtonPressed, - // this.tooltip, super.key, }); final Attribute attribute; - // final IconData icon; - // final double iconSize; - - // final Color? fillColor; - - // final QuillController controller; - - // final ToggleStyleButtonBuilder childBuilder; - - // ///Specify an icon theme for the icons in the toolbar - // final QuillIconTheme? iconTheme; - - // final VoidCallback? afterButtonPressed; - // final String? tooltip; final QuillToolbarToggleStyleButtonOptions options; - /// Since we can't get the state from the instace of the widget for comparing - /// in [didUpdateWidget] then we will have to store reference here final QuillController controller; @override diff --git a/lib/src/widgets/toolbar/toolbar.dart b/lib/src/widgets/toolbar/toolbar.dart index b9f85a11..9dbee7df 100644 --- a/lib/src/widgets/toolbar/toolbar.dart +++ b/lib/src/widgets/toolbar/toolbar.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import '../../../flutter_quill.dart'; -import '../../utils/extensions/build_context.dart'; class QuillToolbar extends StatelessWidget { const QuillToolbar({