Fixes toolbar buttons stealing focus from editor. (#956)

pull/962/head
Benjamin Quinn 3 years ago committed by GitHub
parent a855f59922
commit ab6174d8fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .gitignore
  2. 65
      .vscode/launch.json
  3. 3
      example/lib/pages/home_page.dart
  4. 2
      example/linux/flutter/CMakeLists.txt
  5. 45
      lib/src/widgets/toolbar.dart
  6. 36
      lib/src/widgets/toolbar/clear_format_button.dart
  7. 3
      lib/src/widgets/toolbar/color_button.dart
  8. 3
      lib/src/widgets/toolbar/history_button.dart
  9. 3
      lib/src/widgets/toolbar/indent_button.dart
  10. 3
      lib/src/widgets/toolbar/link_style_button.dart
  11. 7
      lib/src/widgets/toolbar/quill_font_family_button.dart
  12. 7
      lib/src/widgets/toolbar/quill_font_size_button.dart
  13. 7
      lib/src/widgets/toolbar/quill_icon_button.dart
  14. 3
      lib/src/widgets/toolbar/search_button.dart
  15. 13
      lib/src/widgets/toolbar/select_alignment_button.dart
  16. 3
      lib/src/widgets/toolbar/select_header_style_button.dart
  17. 3
      lib/src/widgets/toolbar/toggle_check_list_button.dart
  18. 11
      lib/src/widgets/toolbar/toggle_style_button.dart

2
.gitignore vendored

@ -18,7 +18,7 @@
# The .vscode folder contains launch configuration and tasks you configure in # The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line # VS Code which you may wish to be included in version control, so this line
# is commented out by default. # is commented out by default.
#.vscode/ .vscode/
# Flutter/Dart/Pub related # Flutter/Dart/Pub related
**/doc/api/ **/doc/api/

@ -0,0 +1,65 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "flutter-quill",
"request": "launch",
"type": "dart"
},
{
"name": "flutter-quill (profile mode)",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "flutter-quill (release mode)",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "example",
"cwd": "example",
"request": "launch",
"type": "dart"
},
{
"name": "example (profile mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "example (release mode)",
"cwd": "example",
"request": "launch",
"type": "dart",
"flutterMode": "release"
},
{
"name": "flutter_quill_extensions",
"cwd": "flutter_quill_extensions",
"request": "launch",
"type": "dart"
},
{
"name": "flutter_quill_extensions (profile mode)",
"cwd": "flutter_quill_extensions",
"request": "launch",
"type": "dart",
"flutterMode": "profile"
},
{
"name": "flutter_quill_extensions (release mode)",
"cwd": "flutter_quill_extensions",
"request": "launch",
"type": "dart",
"flutterMode": "release"
}
]
}

@ -169,6 +169,7 @@ class _HomePageState extends State<HomePage> {
// cameraPickSettingSelector: _selectCameraPickSetting, // cameraPickSettingSelector: _selectCameraPickSetting,
), ),
showAlignmentButtons: true, showAlignmentButtons: true,
afterButtonPressed: _focusNode.requestFocus,
); );
if (kIsWeb) { if (kIsWeb) {
toolbar = QuillToolbar.basic( toolbar = QuillToolbar.basic(
@ -178,6 +179,7 @@ class _HomePageState extends State<HomePage> {
webImagePickImpl: _webImagePickImpl, webImagePickImpl: _webImagePickImpl,
), ),
showAlignmentButtons: true, showAlignmentButtons: true,
afterButtonPressed: _focusNode.requestFocus,
); );
} }
if (_isDesktop()) { if (_isDesktop()) {
@ -188,6 +190,7 @@ class _HomePageState extends State<HomePage> {
filePickImpl: openFileSystemPickerForDesktop, filePickImpl: openFileSystemPickerForDesktop,
), ),
showAlignmentButtons: true, showAlignmentButtons: true,
afterButtonPressed: _focusNode.requestFocus,
); );
} }

@ -82,7 +82,7 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E env COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT} ${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
linux-x64 ${CMAKE_BUILD_TYPE} ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
VERBATIM VERBATIM
) )
add_custom_target(flutter_assemble DEPENDS add_custom_target(flutter_assemble DEPENDS

@ -52,6 +52,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
this.color, this.color,
this.customButtons = const [], this.customButtons = const [],
this.locale, this.locale,
VoidCallback? afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -108,6 +109,10 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
///shown when embedding an image, for example ///shown when embedding an image, for example
QuillDialogTheme? dialogTheme, QuillDialogTheme? dialogTheme,
/// Callback to be called after any button on the toolbar is pressed.
/// Is called after whatever logic the button performs has run.
VoidCallback? afterButtonPressed,
/// The locale to use for the editor toolbar, defaults to system locale /// The locale to use for the editor toolbar, defaults to system locale
/// More at https://github.com/singerdmx/flutter-quill#translation /// More at https://github.com/singerdmx/flutter-quill#translation
Locale? locale, Locale? locale,
@ -168,6 +173,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
multiRowsDisplay: multiRowsDisplay, multiRowsDisplay: multiRowsDisplay,
customButtons: customButtons, customButtons: customButtons,
locale: locale, locale: locale,
afterButtonPressed: afterButtonPressed,
children: [ children: [
if (showUndo) if (showUndo)
HistoryButton( HistoryButton(
@ -176,6 +182,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
controller: controller, controller: controller,
undo: true, undo: true,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showRedo) if (showRedo)
HistoryButton( HistoryButton(
@ -184,6 +191,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
controller: controller, controller: controller,
undo: false, undo: false,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showFontFamily) if (showFontFamily)
QuillFontFamilyButton( QuillFontFamilyButton(
@ -207,6 +215,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
'font', newFont == 'Clear' ? null : newFont)); 'font', newFont == 'Clear' ? null : newFont));
}, },
rawItemsMap: fontFamilies, rawItemsMap: fontFamilies,
afterButtonPressed: afterButtonPressed,
), ),
if (showFontSize) if (showFontSize)
QuillFontSizeButton( QuillFontSizeButton(
@ -229,6 +238,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
'size', newSize == '0' ? null : getFontSize(newSize))); 'size', newSize == '0' ? null : getFontSize(newSize)));
}, },
rawItemsMap: fontSizes, rawItemsMap: fontSizes,
afterButtonPressed: afterButtonPressed,
), ),
if (showBoldButton) if (showBoldButton)
ToggleStyleButton( ToggleStyleButton(
@ -237,6 +247,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showItalicButton) if (showItalicButton)
ToggleStyleButton( ToggleStyleButton(
@ -245,6 +256,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showSmallButton) if (showSmallButton)
ToggleStyleButton( ToggleStyleButton(
@ -253,6 +265,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showUnderLineButton) if (showUnderLineButton)
ToggleStyleButton( ToggleStyleButton(
@ -261,6 +274,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showStrikeThrough) if (showStrikeThrough)
ToggleStyleButton( ToggleStyleButton(
@ -269,6 +283,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showInlineCode) if (showInlineCode)
ToggleStyleButton( ToggleStyleButton(
@ -277,6 +292,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showColorButton) if (showColorButton)
ColorButton( ColorButton(
@ -285,6 +301,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
controller: controller, controller: controller,
background: false, background: false,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showBackgroundColorButton) if (showBackgroundColorButton)
ColorButton( ColorButton(
@ -293,6 +310,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
controller: controller, controller: controller,
background: true, background: true,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showClearFormat) if (showClearFormat)
ClearFormatButton( ClearFormatButton(
@ -300,6 +318,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
controller: controller, controller: controller,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (embedButtons != null) if (embedButtons != null)
for (final builder in embedButtons) for (final builder in embedButtons)
@ -325,6 +344,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
showCenterAlignment: showCenterAlignment, showCenterAlignment: showCenterAlignment,
showRightAlignment: showRightAlignment, showRightAlignment: showRightAlignment,
showJustifyAlignment: showJustifyAlignment, showJustifyAlignment: showJustifyAlignment,
afterButtonPressed: afterButtonPressed,
), ),
if (showDirection) if (showDirection)
ToggleStyleButton( ToggleStyleButton(
@ -333,6 +353,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
icon: Icons.format_textdirection_r_to_l, icon: Icons.format_textdirection_r_to_l,
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showDividers && if (showDividers &&
isButtonGroupShown[1] && isButtonGroupShown[1] &&
@ -350,6 +371,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
controller: controller, controller: controller,
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showDividers && if (showDividers &&
showHeaderStyle && showHeaderStyle &&
@ -369,6 +391,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
icon: Icons.format_list_numbered, icon: Icons.format_list_numbered,
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showListBullets) if (showListBullets)
ToggleStyleButton( ToggleStyleButton(
@ -377,6 +400,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
icon: Icons.format_list_bulleted, icon: Icons.format_list_bulleted,
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showListCheck) if (showListCheck)
ToggleCheckListButton( ToggleCheckListButton(
@ -385,6 +409,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
icon: Icons.check_box, icon: Icons.check_box,
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showCodeBlock) if (showCodeBlock)
ToggleStyleButton( ToggleStyleButton(
@ -393,6 +418,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
icon: Icons.code, icon: Icons.code,
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showDividers && if (showDividers &&
isButtonGroupShown[3] && isButtonGroupShown[3] &&
@ -409,6 +435,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
icon: Icons.format_quote, icon: Icons.format_quote,
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showIndent) if (showIndent)
IndentButton( IndentButton(
@ -417,6 +444,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
controller: controller, controller: controller,
isIncrease: true, isIncrease: true,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showIndent) if (showIndent)
IndentButton( IndentButton(
@ -425,6 +453,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
controller: controller, controller: controller,
isIncrease: false, isIncrease: false,
iconTheme: iconTheme, iconTheme: iconTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showDividers && isButtonGroupShown[4] && isButtonGroupShown[5]) if (showDividers && isButtonGroupShown[4] && isButtonGroupShown[5])
VerticalDivider( VerticalDivider(
@ -438,6 +467,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
iconSize: toolbarIconSize, iconSize: toolbarIconSize,
iconTheme: iconTheme, iconTheme: iconTheme,
dialogTheme: dialogTheme, dialogTheme: dialogTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (showSearchButton) if (showSearchButton)
SearchButton( SearchButton(
@ -446,6 +476,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
controller: controller, controller: controller,
iconTheme: iconTheme, iconTheme: iconTheme,
dialogTheme: dialogTheme, dialogTheme: dialogTheme,
afterButtonPressed: afterButtonPressed,
), ),
if (customButtons.isNotEmpty) if (customButtons.isNotEmpty)
if (showDividers) if (showDividers)
@ -456,12 +487,14 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
), ),
for (var customButton in customButtons) for (var customButton in customButtons)
QuillIconButton( QuillIconButton(
highlightElevation: 0, highlightElevation: 0,
hoverElevation: 0, hoverElevation: 0,
size: toolbarIconSize * kIconButtonFactor, size: toolbarIconSize * kIconButtonFactor,
icon: Icon(customButton.icon, size: toolbarIconSize), icon: Icon(customButton.icon, size: toolbarIconSize),
borderRadius: iconTheme?.borderRadius ?? 2, borderRadius: iconTheme?.borderRadius ?? 2,
onPressed: customButton.onTap), onPressed: customButton.onTap,
afterPressed: afterButtonPressed,
),
], ],
); );
} }

@ -8,6 +8,7 @@ class ClearFormatButton extends StatefulWidget {
required this.controller, required this.controller,
this.iconSize = kDefaultIconSize, this.iconSize = kDefaultIconSize,
this.iconTheme, this.iconTheme,
this.afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -17,6 +18,7 @@ class ClearFormatButton extends StatefulWidget {
final QuillController controller; final QuillController controller;
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final VoidCallback? afterButtonPressed;
@override @override
_ClearFormatButtonState createState() => _ClearFormatButtonState(); _ClearFormatButtonState createState() => _ClearFormatButtonState();
@ -31,22 +33,24 @@ class _ClearFormatButtonState extends State<ClearFormatButton> {
final fillColor = final fillColor =
widget.iconTheme?.iconUnselectedFillColor ?? theme.canvasColor; widget.iconTheme?.iconUnselectedFillColor ?? theme.canvasColor;
return QuillIconButton( return QuillIconButton(
highlightElevation: 0, highlightElevation: 0,
hoverElevation: 0, hoverElevation: 0,
size: widget.iconSize * kIconButtonFactor, size: widget.iconSize * kIconButtonFactor,
icon: Icon(widget.icon, size: widget.iconSize, color: iconColor), icon: Icon(widget.icon, size: widget.iconSize, color: iconColor),
fillColor: fillColor, fillColor: fillColor,
borderRadius: widget.iconTheme?.borderRadius ?? 2, borderRadius: widget.iconTheme?.borderRadius ?? 2,
onPressed: () { onPressed: () {
final attrs = <Attribute>{}; final attrs = <Attribute>{};
for (final style in widget.controller.getAllSelectionStyles()) { for (final style in widget.controller.getAllSelectionStyles()) {
for (final attr in style.attributes.values) { for (final attr in style.attributes.values) {
attrs.add(attr); attrs.add(attr);
}
} }
for (final attr in attrs) { }
widget.controller.formatSelection(Attribute.clone(attr, null)); for (final attr in attrs) {
} widget.controller.formatSelection(Attribute.clone(attr, null));
}); }
},
afterPressed: widget.afterButtonPressed,
);
} }
} }

@ -20,6 +20,7 @@ class ColorButton extends StatefulWidget {
required this.background, required this.background,
this.iconSize = kDefaultIconSize, this.iconSize = kDefaultIconSize,
this.iconTheme, this.iconTheme,
this.afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -28,6 +29,7 @@ class ColorButton extends StatefulWidget {
final bool background; final bool background;
final QuillController controller; final QuillController controller;
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final VoidCallback? afterButtonPressed;
@override @override
_ColorButtonState createState() => _ColorButtonState(); _ColorButtonState createState() => _ColorButtonState();
@ -126,6 +128,7 @@ class _ColorButtonState extends State<ColorButton> {
fillColor: widget.background ? fillColorBackground : fillColor, fillColor: widget.background ? fillColorBackground : fillColor,
borderRadius: widget.iconTheme?.borderRadius ?? 2, borderRadius: widget.iconTheme?.borderRadius ?? 2,
onPressed: _showColorPicker, onPressed: _showColorPicker,
afterPressed: widget.afterButtonPressed,
); );
} }

@ -9,6 +9,7 @@ class HistoryButton extends StatefulWidget {
required this.undo, required this.undo,
this.iconSize = kDefaultIconSize, this.iconSize = kDefaultIconSize,
this.iconTheme, this.iconTheme,
this.afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -17,6 +18,7 @@ class HistoryButton extends StatefulWidget {
final bool undo; final bool undo;
final QuillController controller; final QuillController controller;
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final VoidCallback? afterButtonPressed;
@override @override
_HistoryButtonState createState() => _HistoryButtonState(); _HistoryButtonState createState() => _HistoryButtonState();
@ -44,6 +46,7 @@ class _HistoryButtonState extends State<HistoryButton> {
fillColor: fillColor, fillColor: fillColor,
borderRadius: widget.iconTheme?.borderRadius ?? 2, borderRadius: widget.iconTheme?.borderRadius ?? 2,
onPressed: _changeHistory, onPressed: _changeHistory,
afterPressed: widget.afterButtonPressed,
); );
} }

@ -9,6 +9,7 @@ class IndentButton extends StatefulWidget {
required this.isIncrease, required this.isIncrease,
this.iconSize = kDefaultIconSize, this.iconSize = kDefaultIconSize,
this.iconTheme, this.iconTheme,
this.afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -16,6 +17,7 @@ class IndentButton extends StatefulWidget {
final double iconSize; final double iconSize;
final QuillController controller; final QuillController controller;
final bool isIncrease; final bool isIncrease;
final VoidCallback? afterButtonPressed;
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
@ -62,6 +64,7 @@ class _IndentButtonState extends State<IndentButton> {
widget.controller widget.controller
.formatSelection(Attribute.getIndentLevel(indent.value - 1)); .formatSelection(Attribute.getIndentLevel(indent.value - 1));
}, },
afterPressed: widget.afterButtonPressed,
); );
} }
} }

@ -17,6 +17,7 @@ class LinkStyleButton extends StatefulWidget {
this.icon, this.icon,
this.iconTheme, this.iconTheme,
this.dialogTheme, this.dialogTheme,
this.afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -25,6 +26,7 @@ class LinkStyleButton extends StatefulWidget {
final double iconSize; final double iconSize;
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final QuillDialogTheme? dialogTheme; final QuillDialogTheme? dialogTheme;
final VoidCallback? afterButtonPressed;
@override @override
_LinkStyleButtonState createState() => _LinkStyleButtonState(); _LinkStyleButtonState createState() => _LinkStyleButtonState();
@ -79,6 +81,7 @@ class _LinkStyleButtonState extends State<LinkStyleButton> {
: (widget.iconTheme?.iconUnselectedFillColor ?? theme.canvasColor), : (widget.iconTheme?.iconUnselectedFillColor ?? theme.canvasColor),
borderRadius: widget.iconTheme?.borderRadius ?? 2, borderRadius: widget.iconTheme?.borderRadius ?? 2,
onPressed: pressedHandler, onPressed: pressedHandler,
afterPressed: widget.afterButtonPressed,
); );
} }

@ -18,6 +18,7 @@ class QuillFontFamilyButton extends StatefulWidget {
this.hoverElevation = 1, this.hoverElevation = 1,
this.highlightElevation = 1, this.highlightElevation = 1,
this.iconTheme, this.iconTheme,
this.afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -31,6 +32,7 @@ class QuillFontFamilyButton extends StatefulWidget {
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final Attribute attribute; final Attribute attribute;
final QuillController controller; final QuillController controller;
final VoidCallback? afterButtonPressed;
@override @override
_QuillFontFamilyButtonState createState() => _QuillFontFamilyButtonState(); _QuillFontFamilyButtonState createState() => _QuillFontFamilyButtonState();
@ -95,7 +97,10 @@ class _QuillFontFamilyButtonState extends State<QuillFontFamilyButton> {
elevation: 0, elevation: 0,
hoverElevation: widget.hoverElevation, hoverElevation: widget.hoverElevation,
highlightElevation: widget.hoverElevation, highlightElevation: widget.hoverElevation,
onPressed: _showMenu, onPressed: () {
_showMenu();
widget.afterButtonPressed?.call();
},
child: _buildContent(context), child: _buildContent(context),
), ),
); );

@ -19,6 +19,7 @@ class QuillFontSizeButton extends StatefulWidget {
this.hoverElevation = 1, this.hoverElevation = 1,
this.highlightElevation = 1, this.highlightElevation = 1,
this.iconTheme, this.iconTheme,
this.afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -32,6 +33,7 @@ class QuillFontSizeButton extends StatefulWidget {
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final Attribute attribute; final Attribute attribute;
final QuillController controller; final QuillController controller;
final VoidCallback? afterButtonPressed;
@override @override
_QuillFontSizeButtonState createState() => _QuillFontSizeButtonState(); _QuillFontSizeButtonState createState() => _QuillFontSizeButtonState();
@ -96,7 +98,10 @@ class _QuillFontSizeButtonState extends State<QuillFontSizeButton> {
elevation: 0, elevation: 0,
hoverElevation: widget.hoverElevation, hoverElevation: widget.hoverElevation,
highlightElevation: widget.hoverElevation, highlightElevation: widget.hoverElevation,
onPressed: _showMenu, onPressed: () {
_showMenu();
widget.afterButtonPressed?.call();
},
child: _buildContent(context), child: _buildContent(context),
), ),
); );

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
class QuillIconButton extends StatelessWidget { class QuillIconButton extends StatelessWidget {
const QuillIconButton({ const QuillIconButton({
required this.onPressed, required this.onPressed,
this.afterPressed,
this.icon, this.icon,
this.size = 40, this.size = 40,
this.fillColor, this.fillColor,
@ -13,6 +14,7 @@ class QuillIconButton extends StatelessWidget {
}) : super(key: key); }) : super(key: key);
final VoidCallback? onPressed; final VoidCallback? onPressed;
final VoidCallback? afterPressed;
final Widget? icon; final Widget? icon;
final double size; final double size;
final Color? fillColor; final Color? fillColor;
@ -32,7 +34,10 @@ class QuillIconButton extends StatelessWidget {
elevation: 0, elevation: 0,
hoverElevation: hoverElevation, hoverElevation: hoverElevation,
highlightElevation: hoverElevation, highlightElevation: hoverElevation,
onPressed: onPressed, onPressed: () {
onPressed?.call();
afterPressed?.call();
},
child: icon, child: icon,
), ),
); );

@ -15,6 +15,7 @@ class SearchButton extends StatelessWidget {
this.fillColor, this.fillColor,
this.iconTheme, this.iconTheme,
this.dialogTheme, this.dialogTheme,
this.afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -26,6 +27,7 @@ class SearchButton extends StatelessWidget {
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final QuillDialogTheme? dialogTheme; final QuillDialogTheme? dialogTheme;
final VoidCallback? afterButtonPressed;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -43,6 +45,7 @@ class SearchButton extends StatelessWidget {
fillColor: iconFillColor, fillColor: iconFillColor,
borderRadius: iconTheme?.borderRadius ?? 2, borderRadius: iconTheme?.borderRadius ?? 2,
onPressed: () => _onPressedHandler(context), onPressed: () => _onPressedHandler(context),
afterPressed: afterButtonPressed,
); );
} }

@ -16,6 +16,7 @@ class SelectAlignmentButton extends StatefulWidget {
this.showCenterAlignment, this.showCenterAlignment,
this.showRightAlignment, this.showRightAlignment,
this.showJustifyAlignment, this.showJustifyAlignment,
this.afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -27,6 +28,7 @@ class SelectAlignmentButton extends StatefulWidget {
final bool? showCenterAlignment; final bool? showCenterAlignment;
final bool? showRightAlignment; final bool? showRightAlignment;
final bool? showJustifyAlignment; final bool? showJustifyAlignment;
final VoidCallback? afterButtonPressed;
@override @override
_SelectAlignmentButtonState createState() => _SelectAlignmentButtonState(); _SelectAlignmentButtonState createState() => _SelectAlignmentButtonState();
@ -104,10 +106,13 @@ class _SelectAlignmentButtonState extends State<SelectAlignmentButton> {
theme.toggleableActiveColor) theme.toggleableActiveColor)
: (widget.iconTheme?.iconUnselectedFillColor ?? : (widget.iconTheme?.iconUnselectedFillColor ??
theme.canvasColor), theme.canvasColor),
onPressed: () => _valueAttribute[index] == Attribute.leftAlignment onPressed: () {
? widget.controller _valueAttribute[index] == Attribute.leftAlignment
.formatSelection(Attribute.clone(Attribute.align, null)) ? widget.controller
: widget.controller.formatSelection(_valueAttribute[index]), .formatSelection(Attribute.clone(Attribute.align, null))
: widget.controller.formatSelection(_valueAttribute[index]);
widget.afterButtonPressed?.call();
},
child: Icon( child: Icon(
_valueString[index] == Attribute.leftAlignment.value _valueString[index] == Attribute.leftAlignment.value
? Icons.format_align_left ? Icons.format_align_left

@ -18,6 +18,7 @@ class SelectHeaderStyleButton extends StatefulWidget {
Attribute.h2, Attribute.h2,
Attribute.h3, Attribute.h3,
], ],
this.afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -25,6 +26,7 @@ class SelectHeaderStyleButton extends StatefulWidget {
final double iconSize; final double iconSize;
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final List<Attribute> attributes; final List<Attribute> attributes;
final VoidCallback? afterButtonPressed;
@override @override
_SelectHeaderStyleButtonState createState() => _SelectHeaderStyleButtonState createState() =>
@ -95,6 +97,7 @@ class _SelectHeaderStyleButtonState extends State<SelectHeaderStyleButton> {
? Attribute.header ? Attribute.header
: attribute; : attribute;
widget.controller.formatSelection(_attribute); widget.controller.formatSelection(_attribute);
widget.afterButtonPressed?.call();
}, },
child: Text( child: Text(
_valueToText[attribute] ?? '', _valueToText[attribute] ?? '',

@ -15,6 +15,7 @@ class ToggleCheckListButton extends StatefulWidget {
this.fillColor, this.fillColor,
this.childBuilder = defaultToggleStyleButtonBuilder, this.childBuilder = defaultToggleStyleButtonBuilder,
this.iconTheme, this.iconTheme,
this.afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -30,6 +31,7 @@ class ToggleCheckListButton extends StatefulWidget {
final Attribute attribute; final Attribute attribute;
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final VoidCallback? afterButtonPressed;
@override @override
_ToggleCheckListButtonState createState() => _ToggleCheckListButtonState(); _ToggleCheckListButtonState createState() => _ToggleCheckListButtonState();
@ -96,6 +98,7 @@ class _ToggleCheckListButtonState extends State<ToggleCheckListButton> {
widget.fillColor, widget.fillColor,
_isToggled, _isToggled,
_toggleAttribute, _toggleAttribute,
widget.afterButtonPressed,
widget.iconSize, widget.iconSize,
widget.iconTheme, widget.iconTheme,
); );

@ -12,7 +12,8 @@ typedef ToggleStyleButtonBuilder = Widget Function(
IconData icon, IconData icon,
Color? fillColor, Color? fillColor,
bool? isToggled, bool? isToggled,
VoidCallback? onPressed, [ VoidCallback? onPressed,
VoidCallback? afterPressed, [
double iconSize, double iconSize,
QuillIconTheme? iconTheme, QuillIconTheme? iconTheme,
]); ]);
@ -26,6 +27,7 @@ class ToggleStyleButton extends StatefulWidget {
this.fillColor, this.fillColor,
this.childBuilder = defaultToggleStyleButtonBuilder, this.childBuilder = defaultToggleStyleButtonBuilder,
this.iconTheme, this.iconTheme,
this.afterButtonPressed,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
@ -43,6 +45,8 @@ class ToggleStyleButton extends StatefulWidget {
///Specify an icon theme for the icons in the toolbar ///Specify an icon theme for the icons in the toolbar
final QuillIconTheme? iconTheme; final QuillIconTheme? iconTheme;
final VoidCallback? afterButtonPressed;
@override @override
_ToggleStyleButtonState createState() => _ToggleStyleButtonState(); _ToggleStyleButtonState createState() => _ToggleStyleButtonState();
} }
@ -68,6 +72,7 @@ class _ToggleStyleButtonState extends State<ToggleStyleButton> {
widget.fillColor, widget.fillColor,
_isToggled, _isToggled,
_toggleAttribute, _toggleAttribute,
widget.afterButtonPressed,
widget.iconSize, widget.iconSize,
widget.iconTheme, widget.iconTheme,
); );
@ -117,7 +122,8 @@ Widget defaultToggleStyleButtonBuilder(
IconData icon, IconData icon,
Color? fillColor, Color? fillColor,
bool? isToggled, bool? isToggled,
VoidCallback? onPressed, [ VoidCallback? onPressed,
VoidCallback? afterPressed, [
double iconSize = kDefaultIconSize, double iconSize = kDefaultIconSize,
QuillIconTheme? iconTheme, QuillIconTheme? iconTheme,
]) { ]) {
@ -145,6 +151,7 @@ Widget defaultToggleStyleButtonBuilder(
icon: Icon(icon, size: iconSize, color: iconColor), icon: Icon(icon, size: iconSize, color: iconColor),
fillColor: fill, fillColor: fill,
onPressed: onPressed, onPressed: onPressed,
afterPressed: afterPressed,
borderRadius: iconTheme?.borderRadius ?? 2, borderRadius: iconTheme?.borderRadius ?? 2,
); );
} }

Loading…
Cancel
Save