|
|
|
@ -1,293 +1,192 @@ |
|
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
|
import 'package:i18n_extension/i18n_widget.dart'; |
|
|
|
|
|
|
|
|
|
import '../../../flutter_quill.dart'; |
|
|
|
|
import '../../models/config/toolbar/base_configurations.dart'; |
|
|
|
|
import '../../utils/extensions/build_context.dart'; |
|
|
|
|
import 'buttons/arrow_indicated_list.dart'; |
|
|
|
|
|
|
|
|
|
export '../../models/config/toolbar/buttons/base.dart'; |
|
|
|
|
export '../../models/config/toolbar/configurations.dart'; |
|
|
|
|
export 'buttons/clear_format.dart'; |
|
|
|
|
export 'buttons/color.dart'; |
|
|
|
|
export 'buttons/custom_button.dart'; |
|
|
|
|
export 'buttons/font_family.dart'; |
|
|
|
|
export 'buttons/font_size.dart'; |
|
|
|
|
export 'buttons/history.dart'; |
|
|
|
|
export 'buttons/indent.dart'; |
|
|
|
|
export 'buttons/link_style.dart'; |
|
|
|
|
export 'buttons/link_style2.dart'; |
|
|
|
|
export 'buttons/quill_icon.dart'; |
|
|
|
|
export 'buttons/search/search.dart'; |
|
|
|
|
export 'buttons/select_alignment.dart'; |
|
|
|
|
export 'buttons/select_header_style.dart'; |
|
|
|
|
export 'buttons/toggle_check_list.dart'; |
|
|
|
|
export 'buttons/toggle_style.dart'; |
|
|
|
|
|
|
|
|
|
typedef QuillToolbarChildrenBuilder = List<Widget> Function( |
|
|
|
|
BuildContext context, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { |
|
|
|
|
class QuillToolbar extends StatelessWidget { |
|
|
|
|
const QuillToolbar({ |
|
|
|
|
required this.childrenBuilder, |
|
|
|
|
this.axis = Axis.horizontal, |
|
|
|
|
// this.toolbarSize = kDefaultIconSize * 2, |
|
|
|
|
this.toolbarSectionSpacing = kToolbarSectionSpacing, |
|
|
|
|
this.toolbarIconAlignment = WrapAlignment.center, |
|
|
|
|
this.toolbarIconCrossAlignment = WrapCrossAlignment.center, |
|
|
|
|
this.color, |
|
|
|
|
this.customButtons = const [], |
|
|
|
|
this.sectionDividerColor, |
|
|
|
|
this.sectionDividerSpace, |
|
|
|
|
this.linkDialogAction, |
|
|
|
|
this.decoration, |
|
|
|
|
Key? key, |
|
|
|
|
}) : super(key: key); |
|
|
|
|
|
|
|
|
|
factory QuillToolbar.basic({ |
|
|
|
|
double toolbarSectionSpacing = kToolbarSectionSpacing, |
|
|
|
|
WrapAlignment toolbarIconAlignment = WrapAlignment.center, |
|
|
|
|
WrapCrossAlignment toolbarIconCrossAlignment = WrapCrossAlignment.center, |
|
|
|
|
bool showDividers = true, |
|
|
|
|
bool showFontFamily = true, |
|
|
|
|
bool showFontSize = true, |
|
|
|
|
bool showBoldButton = true, |
|
|
|
|
bool showItalicButton = true, |
|
|
|
|
bool showSmallButton = false, |
|
|
|
|
bool showUnderLineButton = true, |
|
|
|
|
bool showStrikeThrough = true, |
|
|
|
|
bool showInlineCode = true, |
|
|
|
|
bool showColorButton = true, |
|
|
|
|
bool showBackgroundColorButton = true, |
|
|
|
|
bool showClearFormat = true, |
|
|
|
|
bool showAlignmentButtons = false, |
|
|
|
|
bool showLeftAlignment = true, |
|
|
|
|
bool showCenterAlignment = true, |
|
|
|
|
bool showRightAlignment = true, |
|
|
|
|
bool showJustifyAlignment = true, |
|
|
|
|
bool showHeaderStyle = true, |
|
|
|
|
bool showListNumbers = true, |
|
|
|
|
bool showListBullets = true, |
|
|
|
|
bool showListCheck = true, |
|
|
|
|
bool showCodeBlock = true, |
|
|
|
|
bool showQuote = true, |
|
|
|
|
bool showIndent = true, |
|
|
|
|
bool showLink = true, |
|
|
|
|
bool showUndo = true, |
|
|
|
|
bool showRedo = true, |
|
|
|
|
bool showDirection = false, |
|
|
|
|
bool showSearchButton = true, |
|
|
|
|
bool showSubscript = true, |
|
|
|
|
bool showSuperscript = true, |
|
|
|
|
List<QuillCustomButton> customButtons = const [], |
|
|
|
|
|
|
|
|
|
/// The decoration to use for the toolbar. |
|
|
|
|
Decoration? decoration, |
|
|
|
|
|
|
|
|
|
/// Toolbar items to display for controls of embed blocks |
|
|
|
|
List<EmbedButtonBuilder>? embedButtons, |
|
|
|
|
|
|
|
|
|
///The theme to use for the icons in the toolbar, uses type [QuillIconTheme] |
|
|
|
|
QuillIconTheme? iconTheme, |
|
|
|
|
|
|
|
|
|
///The theme to use for the theming of the [LinkDialog()], |
|
|
|
|
///shown when embedding an image, for example |
|
|
|
|
QuillDialogTheme? dialogTheme, |
|
|
|
|
|
|
|
|
|
///Map of tooltips for toolbar buttons |
|
|
|
|
/// |
|
|
|
|
///The example is: |
|
|
|
|
///```dart |
|
|
|
|
/// tooltips = <ToolbarButtons, String>{ |
|
|
|
|
/// ToolbarButtons.undo: 'Undo', |
|
|
|
|
/// ToolbarButtons.redo: 'Redo', |
|
|
|
|
/// } |
|
|
|
|
/// |
|
|
|
|
///``` |
|
|
|
|
/// |
|
|
|
|
/// To disable tooltips just pass empty map as well. |
|
|
|
|
@Deprecated('This is deprecated and will no longer used. ' |
|
|
|
|
'to change the tooltips please pass them in the Quill toolbar button' |
|
|
|
|
' configurations which exists in in the QuillProvider') |
|
|
|
|
Map<ToolbarButtons, String>? tooltips, |
|
|
|
|
|
|
|
|
|
/// The locale to use for the editor toolbar, defaults to system locale |
|
|
|
|
/// More at https://github.com/singerdmx/flutter-quill#translation |
|
|
|
|
Locale? locale, |
|
|
|
|
super.key, |
|
|
|
|
this.configurations = const QuillToolbarConfigurations(), |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
/// The color of the toolbar |
|
|
|
|
Color? color, |
|
|
|
|
/// The configurations for the toolbar widget of flutter quill |
|
|
|
|
final QuillToolbarConfigurations configurations; |
|
|
|
|
|
|
|
|
|
/// The color of the toolbar section divider |
|
|
|
|
Color? sectionDividerColor, |
|
|
|
|
@override |
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
final theEmbedButtons = configurations.embedButtons; |
|
|
|
|
|
|
|
|
|
/// The space occupied by toolbar divider |
|
|
|
|
double? sectionDividerSpace, |
|
|
|
|
Key? key, |
|
|
|
|
}) { |
|
|
|
|
final isButtonGroupShown = [ |
|
|
|
|
showFontFamily || |
|
|
|
|
showFontSize || |
|
|
|
|
showBoldButton || |
|
|
|
|
showItalicButton || |
|
|
|
|
showSmallButton || |
|
|
|
|
showUnderLineButton || |
|
|
|
|
showStrikeThrough || |
|
|
|
|
showInlineCode || |
|
|
|
|
showColorButton || |
|
|
|
|
showBackgroundColorButton || |
|
|
|
|
showClearFormat || |
|
|
|
|
embedButtons?.isNotEmpty == true, |
|
|
|
|
showLeftAlignment || |
|
|
|
|
showCenterAlignment || |
|
|
|
|
showRightAlignment || |
|
|
|
|
showJustifyAlignment || |
|
|
|
|
showDirection, |
|
|
|
|
showHeaderStyle, |
|
|
|
|
showListNumbers || showListBullets || showListCheck || showCodeBlock, |
|
|
|
|
showQuote || showIndent, |
|
|
|
|
showLink || showSearchButton |
|
|
|
|
configurations.showFontFamily || |
|
|
|
|
configurations.showFontSize || |
|
|
|
|
configurations.showBoldButton || |
|
|
|
|
configurations.showItalicButton || |
|
|
|
|
configurations.showSmallButton || |
|
|
|
|
configurations.showUnderLineButton || |
|
|
|
|
configurations.showStrikeThrough || |
|
|
|
|
configurations.showInlineCode || |
|
|
|
|
configurations.showColorButton || |
|
|
|
|
configurations.showBackgroundColorButton || |
|
|
|
|
configurations.showClearFormat || |
|
|
|
|
theEmbedButtons?.isNotEmpty == true, |
|
|
|
|
configurations.showLeftAlignment || |
|
|
|
|
configurations.showCenterAlignment || |
|
|
|
|
configurations.showRightAlignment || |
|
|
|
|
configurations.showJustifyAlignment || |
|
|
|
|
configurations.showDirection, |
|
|
|
|
configurations.showHeaderStyle, |
|
|
|
|
configurations.showListNumbers || |
|
|
|
|
configurations.showListBullets || |
|
|
|
|
configurations.showListCheck || |
|
|
|
|
configurations.showCodeBlock, |
|
|
|
|
configurations.showQuote || configurations.showIndent, |
|
|
|
|
configurations.showLink || configurations.showSearchButton |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
return QuillToolbar( |
|
|
|
|
key: key, |
|
|
|
|
color: color, |
|
|
|
|
decoration: decoration, |
|
|
|
|
toolbarSectionSpacing: toolbarSectionSpacing, |
|
|
|
|
toolbarIconAlignment: toolbarIconAlignment, |
|
|
|
|
toolbarIconCrossAlignment: toolbarIconCrossAlignment, |
|
|
|
|
customButtons: customButtons, |
|
|
|
|
return QuillToolbarProvider( |
|
|
|
|
toolbarConfigurations: configurations, |
|
|
|
|
child: QuillBaseToolbar( |
|
|
|
|
configurations: QuillBaseToolbarConfigurations( |
|
|
|
|
color: configurations.color, |
|
|
|
|
decoration: configurations.decoration, |
|
|
|
|
toolbarSectionSpacing: configurations.toolbarSectionSpacing, |
|
|
|
|
toolbarIconAlignment: configurations.toolbarIconAlignment, |
|
|
|
|
toolbarIconCrossAlignment: configurations.toolbarIconCrossAlignment, |
|
|
|
|
customButtons: configurations.customButtons, |
|
|
|
|
linkDialogAction: configurations.linkDialogAction, |
|
|
|
|
multiRowsDisplay: configurations.multiRowsDisplay, |
|
|
|
|
sectionDividerColor: configurations.sectionDividerColor, |
|
|
|
|
axis: configurations.axis, |
|
|
|
|
sectionDividerSpace: configurations.sectionDividerSpace, |
|
|
|
|
toolbarSize: configurations.toolbarSize, |
|
|
|
|
childrenBuilder: (context) { |
|
|
|
|
final controller = context.requireQuillController; |
|
|
|
|
|
|
|
|
|
final toolbarConfigurations = context.requireQuillToolbarConfigurations; |
|
|
|
|
final toolbarConfigurations = |
|
|
|
|
context.requireQuillToolbarConfigurations; |
|
|
|
|
|
|
|
|
|
final globalIconSize = |
|
|
|
|
toolbarConfigurations.buttonOptions.base.globalIconSize; |
|
|
|
|
|
|
|
|
|
final axis = toolbarConfigurations.axis; |
|
|
|
|
|
|
|
|
|
if (tooltips != null) { |
|
|
|
|
throw UnsupportedError( |
|
|
|
|
'This is deprecated and will no longer used. to change ' |
|
|
|
|
'the tooltips please pass them in the Quill toolbar button' |
|
|
|
|
'configurations which exists in in the QuillProvider', |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
final globalController = context.requireQuillController; |
|
|
|
|
|
|
|
|
|
return [ |
|
|
|
|
if (showUndo) |
|
|
|
|
if (configurations.showUndo) |
|
|
|
|
QuillToolbarHistoryButton( |
|
|
|
|
options: toolbarConfigurations.buttonOptions.undoHistory, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.undoHistory.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.undoHistory.controller ?? |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showRedo) |
|
|
|
|
if (configurations.showRedo) |
|
|
|
|
QuillToolbarHistoryButton( |
|
|
|
|
options: toolbarConfigurations.buttonOptions.redoHistory, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.redoHistory.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.redoHistory.controller ?? |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showFontFamily) |
|
|
|
|
if (configurations.showFontFamily) |
|
|
|
|
QuillToolbarFontFamilyButton( |
|
|
|
|
options: toolbarConfigurations.buttonOptions.fontFamily, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.fontFamily.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.fontFamily.controller ?? |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showFontSize) |
|
|
|
|
if (configurations.showFontSize) |
|
|
|
|
QuillToolbarFontSizeButton( |
|
|
|
|
options: toolbarConfigurations.buttonOptions.fontSize, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.fontFamily.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.fontFamily.controller ?? |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showBoldButton) |
|
|
|
|
if (configurations.showBoldButton) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
attribute: Attribute.bold, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.bold, |
|
|
|
|
controller: toolbarConfigurations.buttonOptions.bold.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.bold.controller ?? |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showSubscript) |
|
|
|
|
if (configurations.showSubscript) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
attribute: Attribute.subscript, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.subscript, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.subscript.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.subscript.controller ?? |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showSuperscript) |
|
|
|
|
if (configurations.showSuperscript) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
attribute: Attribute.superscript, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.superscript, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.superscript.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.superscript.controller ?? |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showItalicButton) |
|
|
|
|
if (configurations.showItalicButton) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
attribute: Attribute.italic, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.italic, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.italic.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showSmallButton) |
|
|
|
|
if (configurations.showSmallButton) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
attribute: Attribute.small, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.small, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.small.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showUnderLineButton) |
|
|
|
|
if (configurations.showUnderLineButton) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
attribute: Attribute.underline, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.underLine, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.underLine.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.underLine.controller ?? |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showStrikeThrough) |
|
|
|
|
if (configurations.showStrikeThrough) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
attribute: Attribute.strikeThrough, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.strikeThrough, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.strikeThrough.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showInlineCode) |
|
|
|
|
if (configurations.showInlineCode) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
attribute: Attribute.inlineCode, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.inlineCode, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.inlineCode.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.inlineCode.controller ?? |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showColorButton) |
|
|
|
|
if (configurations.showColorButton) |
|
|
|
|
QuillToolbarColorButton( |
|
|
|
|
controller: controller, |
|
|
|
|
isBackground: false, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.color, |
|
|
|
|
), |
|
|
|
|
if (showBackgroundColorButton) |
|
|
|
|
if (configurations.showBackgroundColorButton) |
|
|
|
|
QuillToolbarColorButton( |
|
|
|
|
options: toolbarConfigurations.buttonOptions.backgroundColor, |
|
|
|
|
controller: controller, |
|
|
|
|
isBackground: true, |
|
|
|
|
), |
|
|
|
|
if (showClearFormat) |
|
|
|
|
if (configurations.showClearFormat) |
|
|
|
|
QuillToolbarClearFormatButton( |
|
|
|
|
controller: controller, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.clearFormat, |
|
|
|
|
), |
|
|
|
|
if (embedButtons != null) |
|
|
|
|
for (final builder in embedButtons) |
|
|
|
|
builder(controller, globalIconSize, iconTheme, dialogTheme), |
|
|
|
|
if (showDividers && |
|
|
|
|
if (theEmbedButtons != null) |
|
|
|
|
for (final builder in theEmbedButtons) |
|
|
|
|
builder(controller, globalIconSize, configurations.iconTheme, |
|
|
|
|
configurations.dialogTheme), |
|
|
|
|
if (configurations.showDividers && |
|
|
|
|
isButtonGroupShown[0] && |
|
|
|
|
(isButtonGroupShown[1] || |
|
|
|
|
isButtonGroupShown[2] || |
|
|
|
@ -296,14 +195,14 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { |
|
|
|
|
isButtonGroupShown[5])) |
|
|
|
|
QuillToolbarDivider( |
|
|
|
|
axis, |
|
|
|
|
color: sectionDividerColor, |
|
|
|
|
space: sectionDividerSpace, |
|
|
|
|
color: configurations.sectionDividerColor, |
|
|
|
|
space: configurations.sectionDividerSpace, |
|
|
|
|
), |
|
|
|
|
if (showAlignmentButtons) |
|
|
|
|
if (configurations.showAlignmentButtons) |
|
|
|
|
QuillToolbarSelectAlignmentButton( |
|
|
|
|
controller: controller, |
|
|
|
|
options: |
|
|
|
|
toolbarConfigurations.buttonOptions.selectAlignmentButtons, |
|
|
|
|
options: toolbarConfigurations |
|
|
|
|
.buttonOptions.selectAlignmentButtons, |
|
|
|
|
// tooltips: Map.of(buttonTooltips) |
|
|
|
|
// ..removeWhere((key, value) => ![ |
|
|
|
|
// ToolbarButtons.leftAlignment, |
|
|
|
@ -311,20 +210,20 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { |
|
|
|
|
// ToolbarButtons.rightAlignment, |
|
|
|
|
// ToolbarButtons.justifyAlignment, |
|
|
|
|
// ].contains(key)), |
|
|
|
|
showLeftAlignment: showLeftAlignment, |
|
|
|
|
showCenterAlignment: showCenterAlignment, |
|
|
|
|
showRightAlignment: showRightAlignment, |
|
|
|
|
showJustifyAlignment: showJustifyAlignment, |
|
|
|
|
showLeftAlignment: configurations.showLeftAlignment, |
|
|
|
|
showCenterAlignment: configurations.showCenterAlignment, |
|
|
|
|
showRightAlignment: configurations.showRightAlignment, |
|
|
|
|
showJustifyAlignment: configurations.showJustifyAlignment, |
|
|
|
|
), |
|
|
|
|
if (showDirection) |
|
|
|
|
if (configurations.showDirection) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
attribute: Attribute.rtl, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.direction, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.direction.controller ?? |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.direction.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
), |
|
|
|
|
if (showDividers && |
|
|
|
|
if (configurations.showDividers && |
|
|
|
|
isButtonGroupShown[1] && |
|
|
|
|
(isButtonGroupShown[2] || |
|
|
|
|
isButtonGroupShown[3] || |
|
|
|
@ -332,112 +231,115 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { |
|
|
|
|
isButtonGroupShown[5])) |
|
|
|
|
QuillToolbarDivider( |
|
|
|
|
axis, |
|
|
|
|
color: sectionDividerColor, |
|
|
|
|
space: sectionDividerSpace, |
|
|
|
|
color: configurations.sectionDividerColor, |
|
|
|
|
space: configurations.sectionDividerSpace, |
|
|
|
|
), |
|
|
|
|
if (showHeaderStyle) |
|
|
|
|
if (configurations.showHeaderStyle) |
|
|
|
|
QuillToolbarSelectHeaderStyleButtons( |
|
|
|
|
controller: controller, |
|
|
|
|
options: |
|
|
|
|
toolbarConfigurations.buttonOptions.selectHeaderStyleButtons, |
|
|
|
|
// tooltip: buttonTooltips[ToolbarButtons.headerStyle], |
|
|
|
|
// axis: axis, |
|
|
|
|
// iconSize: toolbarIconSize, |
|
|
|
|
// iconTheme: iconTheme, |
|
|
|
|
// afterButtonPressed: afterButtonPressed, |
|
|
|
|
), |
|
|
|
|
if (showDividers && |
|
|
|
|
showHeaderStyle && |
|
|
|
|
options: toolbarConfigurations |
|
|
|
|
.buttonOptions.selectHeaderStyleButtons, |
|
|
|
|
), |
|
|
|
|
if (configurations.showDividers && |
|
|
|
|
configurations.showHeaderStyle && |
|
|
|
|
isButtonGroupShown[2] && |
|
|
|
|
(isButtonGroupShown[3] || |
|
|
|
|
isButtonGroupShown[4] || |
|
|
|
|
isButtonGroupShown[5])) |
|
|
|
|
QuillToolbarDivider( |
|
|
|
|
axis, |
|
|
|
|
color: sectionDividerColor, |
|
|
|
|
space: sectionDividerSpace, |
|
|
|
|
color: configurations.sectionDividerColor, |
|
|
|
|
space: configurations.sectionDividerSpace, |
|
|
|
|
), |
|
|
|
|
if (showListNumbers) |
|
|
|
|
if (configurations.showListNumbers) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
attribute: Attribute.ol, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.listNumbers, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.listNumbers.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.listNumbers.controller ?? |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showListBullets) |
|
|
|
|
if (configurations.showListBullets) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
attribute: Attribute.ul, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.listBullets, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.listBullets.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.listBullets.controller ?? |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showListCheck) |
|
|
|
|
if (configurations.showListCheck) |
|
|
|
|
QuillToolbarToggleCheckListButton( |
|
|
|
|
options: toolbarConfigurations.buttonOptions.toggleCheckList, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.toggleCheckList.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showCodeBlock) |
|
|
|
|
if (configurations.showCodeBlock) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
attribute: Attribute.codeBlock, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.codeBlock, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.codeBlock.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.codeBlock.controller ?? |
|
|
|
|
globalController, |
|
|
|
|
), |
|
|
|
|
if (showDividers && |
|
|
|
|
if (configurations.showDividers && |
|
|
|
|
isButtonGroupShown[3] && |
|
|
|
|
(isButtonGroupShown[4] || isButtonGroupShown[5])) |
|
|
|
|
QuillToolbarDivider(axis, |
|
|
|
|
color: sectionDividerColor, space: sectionDividerSpace), |
|
|
|
|
if (showQuote) |
|
|
|
|
QuillToolbarDivider( |
|
|
|
|
axis, |
|
|
|
|
color: configurations.sectionDividerColor, |
|
|
|
|
space: configurations.sectionDividerSpace, |
|
|
|
|
), |
|
|
|
|
if (configurations.showQuote) |
|
|
|
|
QuillToolbarToggleStyleButton( |
|
|
|
|
options: toolbarConfigurations.buttonOptions.quote, |
|
|
|
|
controller: |
|
|
|
|
toolbarConfigurations.buttonOptions.quote.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
globalController, |
|
|
|
|
attribute: Attribute.blockQuote, |
|
|
|
|
), |
|
|
|
|
if (showIndent) |
|
|
|
|
if (configurations.showIndent) |
|
|
|
|
QuillToolbarIndentButton( |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.indentIncrease.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
globalController, |
|
|
|
|
isIncrease: true, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.indentIncrease, |
|
|
|
|
), |
|
|
|
|
if (showIndent) |
|
|
|
|
if (configurations.showIndent) |
|
|
|
|
QuillToolbarIndentButton( |
|
|
|
|
controller: toolbarConfigurations |
|
|
|
|
.buttonOptions.indentDecrease.controller ?? |
|
|
|
|
context.requireQuillController, |
|
|
|
|
globalController, |
|
|
|
|
isIncrease: false, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.indentDecrease, |
|
|
|
|
), |
|
|
|
|
if (showDividers && isButtonGroupShown[4] && isButtonGroupShown[5]) |
|
|
|
|
QuillToolbarDivider(axis, |
|
|
|
|
color: sectionDividerColor, space: sectionDividerSpace), |
|
|
|
|
if (showLink) |
|
|
|
|
if (configurations.showDividers && |
|
|
|
|
isButtonGroupShown[4] && |
|
|
|
|
isButtonGroupShown[5]) |
|
|
|
|
QuillToolbarDivider( |
|
|
|
|
axis, |
|
|
|
|
color: configurations.sectionDividerColor, |
|
|
|
|
space: configurations.sectionDividerSpace, |
|
|
|
|
), |
|
|
|
|
if (configurations.showLink) |
|
|
|
|
QuillToolbarLinkStyleButton( |
|
|
|
|
controller: controller, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.linkStyle, |
|
|
|
|
), |
|
|
|
|
if (showSearchButton) |
|
|
|
|
if (configurations.showSearchButton) |
|
|
|
|
QuillToolbarSearchButton( |
|
|
|
|
controller: controller, |
|
|
|
|
options: toolbarConfigurations.buttonOptions.search, |
|
|
|
|
), |
|
|
|
|
if (customButtons.isNotEmpty) |
|
|
|
|
if (showDividers) |
|
|
|
|
if (configurations.customButtons.isNotEmpty) |
|
|
|
|
if (configurations.showDividers) |
|
|
|
|
QuillToolbarDivider( |
|
|
|
|
axis, |
|
|
|
|
color: sectionDividerColor, |
|
|
|
|
space: sectionDividerSpace, |
|
|
|
|
color: configurations.sectionDividerColor, |
|
|
|
|
space: configurations.sectionDividerSpace, |
|
|
|
|
), |
|
|
|
|
for (final customButton in customButtons) |
|
|
|
|
for (final customButton in configurations.customButtons) |
|
|
|
|
if (customButton.child != null) ...[ |
|
|
|
|
InkWell( |
|
|
|
|
onTap: customButton.onTap, |
|
|
|
@ -450,135 +352,19 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget { |
|
|
|
|
context.quillToolbarBaseButtonOptions?.iconData, |
|
|
|
|
iconColor: customButton.iconColor, |
|
|
|
|
iconSize: customButton.iconSize ?? globalIconSize, |
|
|
|
|
iconTheme: iconTheme ?? |
|
|
|
|
iconTheme: configurations.iconTheme ?? |
|
|
|
|
context.quillToolbarBaseButtonOptions?.iconTheme, |
|
|
|
|
afterButtonPressed: customButton.afterButtonPressed ?? |
|
|
|
|
context.quillToolbarBaseButtonOptions?.afterButtonPressed, |
|
|
|
|
context |
|
|
|
|
.quillToolbarBaseButtonOptions?.afterButtonPressed, |
|
|
|
|
tooltip: customButton.tooltip ?? |
|
|
|
|
context.quillToolbarBaseButtonOptions?.tooltip, |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
]; |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final QuillToolbarChildrenBuilder childrenBuilder; |
|
|
|
|
final Axis axis; |
|
|
|
|
final double toolbarSectionSpacing; |
|
|
|
|
final WrapAlignment toolbarIconAlignment; |
|
|
|
|
final WrapCrossAlignment toolbarIconCrossAlignment; |
|
|
|
|
|
|
|
|
|
// Overrides the action in the _LinkDialog widget |
|
|
|
|
final LinkDialogAction? linkDialogAction; |
|
|
|
|
|
|
|
|
|
/// The color of the toolbar. |
|
|
|
|
/// |
|
|
|
|
/// Defaults to [ThemeData.canvasColor] of the current [Theme] if no color |
|
|
|
|
/// is given. |
|
|
|
|
final Color? color; |
|
|
|
|
|
|
|
|
|
/// List of custom buttons |
|
|
|
|
final List<QuillCustomButton> customButtons; |
|
|
|
|
|
|
|
|
|
/// The color to use when painting the toolbar section divider. |
|
|
|
|
/// |
|
|
|
|
/// If this is null, then the [DividerThemeData.color] is used. If that is |
|
|
|
|
/// also null, then [ThemeData.dividerColor] is used. |
|
|
|
|
final Color? sectionDividerColor; |
|
|
|
|
|
|
|
|
|
/// The space occupied by toolbar section divider. |
|
|
|
|
final double? sectionDividerSpace; |
|
|
|
|
|
|
|
|
|
/// The decoration to use for the toolbar. |
|
|
|
|
final Decoration? decoration; |
|
|
|
|
|
|
|
|
|
// We can't get the modified [toolbarSize] by the developer |
|
|
|
|
// but I tested the [QuillToolbar] on the [appBar] and I didn't notice |
|
|
|
|
// a difference no matter what the value is so I will leave it to the |
|
|
|
|
// default |
|
|
|
|
@override |
|
|
|
|
Size get preferredSize => axis == Axis.horizontal |
|
|
|
|
? const Size.fromHeight(defaultToolbarSize) |
|
|
|
|
: const Size.fromWidth(defaultToolbarSize); |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
final toolbarConfigurations = context.requireQuillToolbarConfigurations; |
|
|
|
|
final toolbarSize = toolbarConfigurations.toolbarSize; |
|
|
|
|
return I18n( |
|
|
|
|
initialLocale: context.quillSharedConfigurations?.locale, |
|
|
|
|
child: (toolbarConfigurations.multiRowsDisplay) |
|
|
|
|
? Wrap( |
|
|
|
|
direction: axis, |
|
|
|
|
alignment: toolbarIconAlignment, |
|
|
|
|
crossAxisAlignment: toolbarIconCrossAlignment, |
|
|
|
|
runSpacing: 4, |
|
|
|
|
spacing: toolbarSectionSpacing, |
|
|
|
|
children: childrenBuilder(context), |
|
|
|
|
) |
|
|
|
|
: Container( |
|
|
|
|
decoration: decoration ?? |
|
|
|
|
BoxDecoration( |
|
|
|
|
color: color ?? Theme.of(context).canvasColor, |
|
|
|
|
), |
|
|
|
|
constraints: BoxConstraints.tightFor( |
|
|
|
|
height: axis == Axis.horizontal ? toolbarSize : null, |
|
|
|
|
width: axis == Axis.vertical ? toolbarSize : null, |
|
|
|
|
), |
|
|
|
|
child: QuillToolbarArrowIndicatedButtonList( |
|
|
|
|
axis: axis, |
|
|
|
|
buttons: childrenBuilder(context), |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// The divider which is used for separation of buttons in the toolbar. |
|
|
|
|
/// |
|
|
|
|
/// It can be used outside of this package, for example when user does not use |
|
|
|
|
/// [QuillToolbar.basic] and compose toolbar's children on its own. |
|
|
|
|
class QuillToolbarDivider extends StatelessWidget { |
|
|
|
|
const QuillToolbarDivider( |
|
|
|
|
this.axis, { |
|
|
|
|
super.key, |
|
|
|
|
this.color, |
|
|
|
|
this.space, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
/// Provides a horizontal divider for vertical toolbar. |
|
|
|
|
const QuillToolbarDivider.horizontal({Color? color, double? space}) |
|
|
|
|
: this(Axis.horizontal, color: color, space: space); |
|
|
|
|
|
|
|
|
|
/// Provides a horizontal divider for horizontal toolbar. |
|
|
|
|
const QuillToolbarDivider.vertical({Color? color, double? space}) |
|
|
|
|
: this(Axis.vertical, color: color, space: space); |
|
|
|
|
|
|
|
|
|
/// The axis along which the toolbar is. |
|
|
|
|
final Axis axis; |
|
|
|
|
|
|
|
|
|
/// The color to use when painting this divider's line. |
|
|
|
|
final Color? color; |
|
|
|
|
|
|
|
|
|
/// The divider's space (width or height) depending of [axis]. |
|
|
|
|
final double? space; |
|
|
|
|
|
|
|
|
|
@override |
|
|
|
|
Widget build(BuildContext context) { |
|
|
|
|
// Vertical toolbar requires horizontal divider, and vice versa |
|
|
|
|
return axis == Axis.vertical |
|
|
|
|
? Divider( |
|
|
|
|
height: space, |
|
|
|
|
color: color, |
|
|
|
|
indent: 12, |
|
|
|
|
endIndent: 12, |
|
|
|
|
) |
|
|
|
|
: VerticalDivider( |
|
|
|
|
width: space, |
|
|
|
|
color: color, |
|
|
|
|
indent: 12, |
|
|
|
|
endIndent: 12, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|