forked from singerdmx/flutter-quill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
toolbar_configurations.dart
333 lines (297 loc) · 12.2 KB
/
toolbar_configurations.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart' show immutable;
import 'package:flutter/widgets.dart'
show Axis, Widget, WrapAlignment, WrapCrossAlignment;
import '../../../widgets/embeds.dart';
import '../../themes/quill_dialog_theme.dart';
import '../../themes/quill_icon_theme.dart';
import 'buttons/base.dart';
import 'buttons/clear_format.dart';
import 'buttons/color.dart';
import 'buttons/custom_button.dart';
import 'buttons/dropdown_header_style.dart';
import 'buttons/font_family.dart';
import 'buttons/font_size.dart';
import 'buttons/history.dart';
import 'buttons/indent.dart';
import 'buttons/link_style.dart';
import 'buttons/link_style2.dart';
import 'buttons/search.dart';
import 'buttons/select_alignment.dart';
import 'buttons/select_header_style.dart';
import 'buttons/toggle_check_list.dart';
import 'buttons/toggle_style.dart';
import 'toolbar_shared_configurations.dart';
export './../../../widgets/toolbar/buttons/search/search_dialog.dart';
export './buttons/base.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/search.dart';
export './buttons/select_alignment.dart';
export './buttons/select_header_style.dart';
export './buttons/dropdown_header_style.dart';
export './buttons/toggle_check_list.dart';
export './buttons/toggle_style.dart';
/// The default size of the icon of a button.
const double kDefaultIconSize = 18;
/// The default size for the toolbar (width, height)
const double defaultToolbarSize = kDefaultIconSize * 2;
/// The factor of how much larger the button is in relation to the icon.
const double kIconButtonFactor = 1.77;
/// The horizontal margin between the contents of each toolbar section.
const double kToolbarSectionSpacing = 4;
enum LinkStyleType {
/// Defines the original [QuillToolbarLinkStyleButton].
original,
/// Defines the alternative [QuillToolbarLinkStyleButton2].
alternative;
bool get isOriginal => this == LinkStyleType.original;
bool get isAlternative => this == LinkStyleType.alternative;
}
enum HeaderStyleType {
/// Defines the original [QuillToolbarSelectHeaderStyleButtons].
original,
/// Defines the alternative [QuillToolbarSelectHeaderStyleDropdownButton].
dropdown;
bool get isOriginal => this == HeaderStyleType.original;
bool get isDropdown => this == HeaderStyleType.dropdown;
}
/// The configurations for the toolbar widget of flutter quill
@immutable
class QuillToolbarConfigurations extends QuillSharedToolbarProperties {
const QuillToolbarConfigurations({
super.toolbarSectionSpacing = kToolbarSectionSpacing,
super.toolbarIconAlignment = WrapAlignment.center,
super.toolbarIconCrossAlignment = WrapCrossAlignment.center,
super.buttonOptions = const QuillToolbarButtonOptions(),
super.multiRowsDisplay = true,
this.fontSizesValues,
this.showDividers = true,
this.showFontFamily = true,
this.showFontSize = true,
this.showBoldButton = true,
this.showItalicButton = true,
this.showSmallButton = false,
this.showUnderLineButton = true,
this.showStrikeThrough = true,
this.showInlineCode = true,
this.showColorButton = true,
this.showBackgroundColorButton = true,
this.showClearFormat = true,
this.showAlignmentButtons = false,
this.showLeftAlignment = true,
this.showCenterAlignment = true,
this.showRightAlignment = true,
this.showJustifyAlignment = true,
this.showHeaderStyle = true,
this.showListNumbers = true,
this.showListBullets = true,
this.showListCheck = true,
this.showCodeBlock = true,
this.showQuote = true,
this.showIndent = true,
this.showLink = true,
this.showUndo = true,
this.showRedo = true,
this.showDirection = false,
this.showSearchButton = true,
this.showSubscript = true,
this.showSuperscript = true,
this.linkStyleType = LinkStyleType.original,
this.headerStyleType = HeaderStyleType.original,
super.customButtons = const [],
/// The decoration to use for the toolbar.
super.decoration,
/// Toolbar items to display for controls of embed blocks
this.embedButtons,
super.linkDialogAction,
///The theme to use for the icons in the toolbar, uses type [QuillIconTheme]
// this.iconTheme,
this.dialogTheme,
super.axis = Axis.horizontal,
super.color,
super.sectionDividerColor,
super.sectionDividerSpace,
this.spacerWidget,
/// By default it will calculated based on the [globalIconSize] from
/// [base] in [QuillToolbarButtonOptions]
/// You can change it but the the change only apply if
/// the [multiRowsDisplay] is false, if [multiRowsDisplay] then the value
/// will be [kDefaultIconSize] * 2
super.toolbarSize,
}) : _toolbarSize = toolbarSize;
final double? _toolbarSize;
/// The toolbar size, by default it will be `baseButtonOptions.iconSize * 2`
@override
double get toolbarSize {
final alternativeToolbarSize = _toolbarSize;
if (alternativeToolbarSize != null) {
return alternativeToolbarSize;
}
return buttonOptions.base.globalIconSize * 2;
}
/// A widget that will placed between each button in the toolbar
/// can be used as a spacer
/// it will not used before the first button
/// it will not used after the last button
/// it will also not used in the toolbar dividers
/// Default value will be [SizedBox.shrink()]
/// some widgets like the header styles will be considered as one widget
final Widget? spacerWidget;
/// By default it will be
/// ```
/// {
/// 'Small'.i18n: 'small',
/// 'Large'.i18n: 'large',
/// 'Huge'.i18n: 'huge',
/// 'Clear'.loc: '0'
/// }
/// ```
final Map<String, String>? fontSizesValues;
final bool showDividers;
final bool showFontFamily;
final bool showFontSize;
final bool showBoldButton;
final bool showItalicButton;
final bool showSmallButton;
final bool showUnderLineButton;
final bool showStrikeThrough;
final bool showInlineCode;
final bool showColorButton;
final bool showBackgroundColorButton;
final bool showClearFormat;
final bool showAlignmentButtons;
final bool showLeftAlignment;
final bool showCenterAlignment;
final bool showRightAlignment;
final bool showJustifyAlignment;
final bool showHeaderStyle;
final bool showListNumbers;
final bool showListBullets;
final bool showListCheck;
final bool showCodeBlock;
final bool showQuote;
final bool showIndent;
final bool showLink;
final bool showUndo;
final bool showRedo;
final bool showDirection;
final bool showSearchButton;
final bool showSubscript;
final bool showSuperscript;
/// Toolbar items to display for controls of embed blocks
final List<EmbedButtonBuilder>? embedButtons;
// ///The theme to use for the icons in the toolbar, uses type [QuillIconTheme]
// final QuillIconTheme? iconTheme;
///The theme to use for the theming of the [LinkDialog()],
///shown when embedding an image, for example
final QuillDialogTheme? dialogTheme;
/// Defines which dialog is used for applying link attribute.
final LinkStyleType linkStyleType;
/// Defines which dialog is used for applying header attribute.
final HeaderStyleType headerStyleType;
@override
List<Object?> get props => [
buttonOptions,
multiRowsDisplay,
fontSizesValues,
toolbarSize,
axis,
];
}
/// The configurations for the buttons of the toolbar widget of flutter quill
@immutable
class QuillToolbarButtonOptions extends Equatable {
const QuillToolbarButtonOptions({
this.base = const QuillToolbarBaseButtonOptions(),
this.undoHistory = const QuillToolbarHistoryButtonOptions(
isUndo: true,
),
this.redoHistory = const QuillToolbarHistoryButtonOptions(
isUndo: false,
),
this.fontFamily = const QuillToolbarFontFamilyButtonOptions(),
this.fontSize = const QuillToolbarFontSizeButtonOptions(),
this.bold = const QuillToolbarToggleStyleButtonOptions(),
this.subscript = const QuillToolbarToggleStyleButtonOptions(),
this.superscript = const QuillToolbarToggleStyleButtonOptions(),
this.italic = const QuillToolbarToggleStyleButtonOptions(),
this.small = const QuillToolbarToggleStyleButtonOptions(),
this.underLine = const QuillToolbarToggleStyleButtonOptions(),
this.strikeThrough = const QuillToolbarToggleStyleButtonOptions(),
this.inlineCode = const QuillToolbarToggleStyleButtonOptions(),
this.direction = const QuillToolbarToggleStyleButtonOptions(),
this.listNumbers = const QuillToolbarToggleStyleButtonOptions(),
this.listBullets = const QuillToolbarToggleStyleButtonOptions(),
this.codeBlock = const QuillToolbarToggleStyleButtonOptions(),
this.quote = const QuillToolbarToggleStyleButtonOptions(),
this.toggleCheckList = const QuillToolbarToggleCheckListButtonOptions(),
this.indentIncrease = const QuillToolbarIndentButtonOptions(),
this.indentDecrease = const QuillToolbarIndentButtonOptions(),
this.color = const QuillToolbarColorButtonOptions(),
this.backgroundColor = const QuillToolbarColorButtonOptions(),
this.clearFormat = const QuillToolbarClearFormatButtonOptions(),
this.selectAlignmentButtons =
const QuillToolbarSelectAlignmentButtonOptions(),
this.search = const QuillToolbarSearchButtonOptions(),
this.selectHeaderStyleButtons =
const QuillToolbarSelectHeaderStyleButtonsOptions(),
this.headerStyleButton =
const QuillToolbarSelectHeaderStyleDropdownButtonOptions(),
this.linkStyle = const QuillToolbarLinkStyleButtonOptions(),
this.linkStyle2 = const QuillToolbarLinkStyleButton2Options(),
this.customButtons = const QuillToolbarCustomButtonOptions(),
});
/// The base configurations for all the buttons which will apply to all
/// but if the options overrided in the spesefic button options
/// then it will use that instead
final QuillToolbarBaseButtonOptions base;
final QuillToolbarHistoryButtonOptions undoHistory;
final QuillToolbarHistoryButtonOptions redoHistory;
final QuillToolbarFontFamilyButtonOptions fontFamily;
final QuillToolbarFontSizeButtonOptions fontSize;
final QuillToolbarToggleStyleButtonOptions bold;
final QuillToolbarToggleStyleButtonOptions subscript;
final QuillToolbarToggleStyleButtonOptions superscript;
final QuillToolbarToggleStyleButtonOptions italic;
final QuillToolbarToggleStyleButtonOptions small;
final QuillToolbarToggleStyleButtonOptions underLine;
final QuillToolbarToggleStyleButtonOptions strikeThrough;
final QuillToolbarToggleStyleButtonOptions inlineCode;
final QuillToolbarToggleStyleButtonOptions direction;
final QuillToolbarToggleStyleButtonOptions listNumbers;
final QuillToolbarToggleStyleButtonOptions listBullets;
final QuillToolbarToggleStyleButtonOptions codeBlock;
final QuillToolbarToggleStyleButtonOptions quote;
final QuillToolbarToggleCheckListButtonOptions toggleCheckList;
final QuillToolbarIndentButtonOptions indentIncrease;
final QuillToolbarIndentButtonOptions indentDecrease;
final QuillToolbarColorButtonOptions color;
final QuillToolbarColorButtonOptions backgroundColor;
final QuillToolbarClearFormatButtonOptions clearFormat;
/// The reason we call this buttons in the end because this is responsible
/// for all the alignment buttons and not just one, you still
/// can customize the icons and tooltips
/// and you have child builder
final QuillToolbarSelectAlignmentButtonOptions selectAlignmentButtons;
final QuillToolbarSearchButtonOptions search;
/// The reason we call this buttons in the end because this is responsible
/// for all the header style buttons and not just one, you still
/// can customize it and you also have child builder
final QuillToolbarSelectHeaderStyleButtonsOptions selectHeaderStyleButtons;
final QuillToolbarSelectHeaderStyleDropdownButtonOptions headerStyleButton;
final QuillToolbarLinkStyleButtonOptions linkStyle;
final QuillToolbarLinkStyleButton2Options linkStyle2;
final QuillToolbarCustomButtonOptions customButtons;
@override
List<Object?> get props => [
base,
];
}