From 4fe42579066f6e173a0e6dab18b5029aebee5227 Mon Sep 17 00:00:00 2001 From: mark8044 <87546778+mark8044@users.noreply.github.com> Date: Mon, 9 May 2022 20:47:01 -0700 Subject: [PATCH] This adds a new CustomIcons option to add your own icons to the QuillToolBar (#804) --- lib/flutter_quill.dart | 1 + lib/src/models/themes/quill_custom_icon.dart | 13 +++++++++++ lib/src/widgets/toolbar.dart | 24 ++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 lib/src/models/themes/quill_custom_icon.dart diff --git a/lib/flutter_quill.dart b/lib/flutter_quill.dart index faf55b3e..c38ea4df 100644 --- a/lib/flutter_quill.dart +++ b/lib/flutter_quill.dart @@ -8,6 +8,7 @@ export 'src/models/documents/style.dart'; export 'src/models/quill_delta.dart'; export 'src/models/themes/quill_dialog_theme.dart'; export 'src/models/themes/quill_icon_theme.dart'; +export 'src/models/themes/quill_custom_icon.dart'; export 'src/widgets/controller.dart'; export 'src/widgets/default_styles.dart'; export 'src/widgets/editor.dart'; diff --git a/lib/src/models/themes/quill_custom_icon.dart b/lib/src/models/themes/quill_custom_icon.dart new file mode 100644 index 00000000..62b31ffc --- /dev/null +++ b/lib/src/models/themes/quill_custom_icon.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class QuillCustomIcon { + const QuillCustomIcon( + {this.icon, + this.onTap}); + + ///The icon widget + final IconData? icon; + + ///The function when the icon is tapped + final VoidCallback? onTap; +} diff --git a/lib/src/widgets/toolbar.dart b/lib/src/widgets/toolbar.dart index 708f0079..0951221d 100644 --- a/lib/src/widgets/toolbar.dart +++ b/lib/src/widgets/toolbar.dart @@ -6,6 +6,7 @@ import 'package:i18n_extension/i18n_widget.dart'; import '../models/documents/attribute.dart'; import '../models/themes/quill_dialog_theme.dart'; import '../models/themes/quill_icon_theme.dart'; +import '../models/themes/quill_custom_icon.dart'; import 'controller.dart'; import 'toolbar/arrow_indicated_button_list.dart'; import 'toolbar/camera_button.dart'; @@ -22,6 +23,7 @@ import 'toolbar/toggle_check_list_button.dart'; import 'toolbar/toggle_style_button.dart'; import 'toolbar/video_button.dart'; import 'toolbar/quill_dropdown_button.dart'; +import 'toolbar/quill_icon_button.dart'; export 'toolbar/clear_format_button.dart'; export 'toolbar/color_button.dart'; @@ -63,6 +65,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { this.multiRowsDisplay = true, this.color, this.filePickImpl, + this.customIcons = const [], this.locale, Key? key, }) : super(key: key); @@ -109,6 +112,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { FilePickImpl? filePickImpl, WebImagePickImpl? webImagePickImpl, WebVideoPickImpl? webVideoPickImpl, + List customIcons = const [], ///Map of font sizes in [int] Map? fontSizeValues, @@ -172,6 +176,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { toolbarSectionSpacing: toolbarSectionSpacing, toolbarIconAlignment: toolbarIconAlignment, multiRowsDisplay: multiRowsDisplay, + customIcons: customIcons, locale: locale, children: [ if (showUndo) @@ -463,6 +468,22 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { iconTheme: iconTheme, dialogTheme: dialogTheme, ), + if (customIcons.isNotEmpty) + if (showDividers) + VerticalDivider( + indent: 12, + endIndent: 12, + color: Colors.grey.shade400, + ), + for (var customIcon in customIcons) + QuillIconButton( + highlightElevation: 0, + hoverElevation: 0, + size: toolbarIconSize * kIconButtonFactor, + icon: Icon(customIcon.icon, size: toolbarIconSize), + borderRadius:iconTheme?.borderRadius ?? 2, + onPressed: customIcon.onTap + ), ], ); } @@ -485,6 +506,9 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { /// More https://github.com/singerdmx/flutter-quill#translation final Locale? locale; + /// List of custom icons + final List customIcons; + @override Size get preferredSize => Size.fromHeight(toolbarHeight);