Skip to content

Commit 71d06f6

Browse files
committed
Support font family selection
1 parent 6a462ee commit 71d06f6

File tree

4 files changed

+222
-4
lines changed

4 files changed

+222
-4
lines changed

lib/src/translations/toolbar.i18n.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extension Localization on String {
2727
'Large': 'Large',
2828
'Huge': 'Huge',
2929
'Clear': 'Clear',
30+
'Font': 'Font',
3031
},
3132
'en_us': {
3233
'Paste a link': 'Paste a link',
@@ -52,6 +53,7 @@ extension Localization on String {
5253
'Large': 'Large',
5354
'Huge': 'Huge',
5455
'Clear': 'Clear',
56+
'Font': 'Font',
5557
},
5658
'ar': {
5759
'Paste a link': 'نسخ الرابط',
@@ -77,6 +79,7 @@ extension Localization on String {
7779
'Large': 'Large',
7880
'Huge': 'Huge',
7981
'Clear': 'Clear',
82+
'Font': 'Font',
8083
},
8184
'da': {
8285
'Paste a link': 'Indsæt link',
@@ -102,6 +105,7 @@ extension Localization on String {
102105
'Large': 'Large',
103106
'Huge': 'Huge',
104107
'Clear': 'Clear',
108+
'Font': 'Font',
105109
},
106110
'de': {
107111
'Paste a link': 'Link hinzufügen',
@@ -128,6 +132,7 @@ extension Localization on String {
128132
'Large': 'Large',
129133
'Huge': 'Huge',
130134
'Clear': 'Clear',
135+
'Font': 'Font',
131136
},
132137
'fr': {
133138
'Paste a link': 'Coller un lien',
@@ -153,6 +158,7 @@ extension Localization on String {
153158
'Large': 'Large',
154159
'Huge': 'Huge',
155160
'Clear': 'Clear',
161+
'Font': 'Font',
156162
},
157163
'zh_CN': {
158164
'Paste a link': '粘贴链接',
@@ -178,6 +184,7 @@ extension Localization on String {
178184
'Large': 'Large',
179185
'Huge': 'Huge',
180186
'Clear': 'Clear',
187+
'Font': 'Font',
181188
},
182189
'ko': {
183190
'Paste a link': '링크를 붙여넣어 주세요.',
@@ -202,6 +209,7 @@ extension Localization on String {
202209
'Large': 'Large',
203210
'Huge': 'Huge',
204211
'Clear': 'Clear',
212+
'Font': 'Font',
205213
},
206214
'ru': {
207215
'Paste a link': 'Вставить ссылку',
@@ -227,6 +235,7 @@ extension Localization on String {
227235
'Large': 'Large',
228236
'Huge': 'Huge',
229237
'Clear': 'Clear',
238+
'Font': 'Font',
230239
},
231240
'es': {
232241
'Paste a link': 'Pega un enlace',
@@ -253,6 +262,7 @@ extension Localization on String {
253262
'Large': 'Large',
254263
'Huge': 'Huge',
255264
'Clear': 'Clear',
265+
'Font': 'Font',
256266
},
257267
'tr': {
258268
'Paste a link': 'Bağlantıyı Yapıştır',
@@ -278,6 +288,7 @@ extension Localization on String {
278288
'Large': 'Large',
279289
'Huge': 'Huge',
280290
'Clear': 'Clear',
291+
'Font': 'Font',
281292
},
282293
'uk': {
283294
'Paste a link': 'Вставити посилання',
@@ -303,6 +314,7 @@ extension Localization on String {
303314
'Large': 'Large',
304315
'Huge': 'Huge',
305316
'Clear': 'Clear',
317+
'Font': 'Font',
306318
},
307319
'pt': {
308320
'Paste a link': 'Colar um link',
@@ -329,6 +341,7 @@ extension Localization on String {
329341
'Large': 'Large',
330342
'Huge': 'Huge',
331343
'Clear': 'Clear',
344+
'Font': 'Font',
332345
},
333346
'pl': {
334347
'Paste a link': 'Wklej link',
@@ -355,6 +368,7 @@ extension Localization on String {
355368
'Large': 'Large',
356369
'Huge': 'Huge',
357370
'Clear': 'Clear',
371+
'Font': 'Font',
358372
},
359373
'vi': {
360374
'Paste a link': 'Chèn liên kết',
@@ -381,6 +395,7 @@ extension Localization on String {
381395
'Large': 'Large',
382396
'Huge': 'Huge',
383397
'Clear': 'Clear',
398+
'Font': 'Font',
384399
},
385400
'ur': {
386401
'Paste a link': 'لنک پیسٹ کریں',
@@ -406,6 +421,7 @@ extension Localization on String {
406421
'Large': 'Large',
407422
'Huge': 'Huge',
408423
'Clear': 'Clear',
424+
'Font': 'Font',
409425
},
410426
'id': {
411427
'Paste a link': 'Tempel tautan',
@@ -431,6 +447,7 @@ extension Localization on String {
431447
'Large': 'Large',
432448
'Huge': 'Huge',
433449
'Clear': 'Clear',
450+
'Font': 'Font',
434451
},
435452
'no': {
436453
'Paste a link': 'Lim inn lenke',
@@ -456,6 +473,7 @@ extension Localization on String {
456473
'Large': 'Large',
457474
'Huge': 'Huge',
458475
'Clear': 'Clear',
476+
'Font': 'Font',
459477
},
460478
'fa': {
461479
'Paste a link': 'جایگذاری لینک',
@@ -481,6 +499,7 @@ extension Localization on String {
481499
'Large': 'Large',
482500
'Huge': 'Huge',
483501
'Clear': 'Clear',
502+
'Font': 'Font',
484503
},
485504
'hi': {
486505
'Paste a link': 'लिंक पेस्ट करें',
@@ -506,6 +525,7 @@ extension Localization on String {
506525
'Large': 'Large',
507526
'Huge': 'Huge',
508527
'Clear': 'Clear',
528+
'Font': 'Font',
509529
},
510530
'nl': {
511531
'Paste a link': 'Plak een link',
@@ -531,6 +551,7 @@ extension Localization on String {
531551
'Large': 'Large',
532552
'Huge': 'Huge',
533553
'Clear': 'Clear',
554+
'Font': 'Font',
534555
},
535556
'zh_HK': {
536557
'Paste a link': '貼上連結',
@@ -556,6 +577,7 @@ extension Localization on String {
556577
'Large': 'Large',
557578
'Huge': 'Huge',
558579
'Clear': 'Clear',
580+
'Font': 'Font',
559581
},
560582
'sr': {
561583
'Paste a link': 'Nalepi vezu',
@@ -581,6 +603,7 @@ extension Localization on String {
581603
'Large': 'Large',
582604
'Huge': 'Huge',
583605
'Clear': 'Clear',
606+
'Font': 'Font',
584607
},
585608
};
586609

lib/src/widgets/toolbar.dart

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import 'toolbar/image_button.dart';
1919
import 'toolbar/image_video_utils.dart';
2020
import 'toolbar/indent_button.dart';
2121
import 'toolbar/link_style_button.dart';
22+
import 'toolbar/quill_font_family_button.dart';
2223
import 'toolbar/quill_font_size_button.dart';
2324
import 'toolbar/quill_icon_button.dart';
2425
import 'toolbar/select_alignment_button.dart';
@@ -78,6 +79,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
7879
double toolbarSectionSpacing = 4,
7980
WrapAlignment toolbarIconAlignment = WrapAlignment.center,
8081
bool showDividers = true,
82+
bool showFontFamily = true,
8183
bool showFontSize = true,
8284
bool showBoldButton = true,
8385
bool showItalicButton = true,
@@ -119,6 +121,9 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
119121
///Map of font sizes in string
120122
Map<String, String>? fontSizeValues,
121123

124+
///Map of font families in string
125+
Map<String, String>? fontFamilyValues,
126+
122127
///The theme to use for the icons in the toolbar, uses type [QuillIconTheme]
123128
QuillIconTheme? iconTheme,
124129

@@ -132,7 +137,8 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
132137
Key? key,
133138
}) {
134139
final isButtonGroupShown = [
135-
showFontSize ||
140+
showFontFamily ||
141+
showFontSize ||
136142
showBoldButton ||
137143
showItalicButton ||
138144
showSmallButton ||
@@ -164,6 +170,15 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
164170
'Clear'.i18n: '0'
165171
};
166172

173+
//default font family values
174+
final fontFamilies = fontFamilyValues ??
175+
{
176+
'Sans Serif': 'sans-serif',
177+
'Serif': 'serif',
178+
'Monospace': 'monospace',
179+
'Clear': 'Clear'
180+
};
181+
167182
return QuillToolbar(
168183
key: key,
169184
toolbarHeight: toolbarIconSize * 2,
@@ -189,6 +204,29 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
189204
undo: false,
190205
iconTheme: iconTheme,
191206
),
207+
if (showFontFamily)
208+
QuillFontFamilyButton(
209+
iconTheme: iconTheme,
210+
iconSize: toolbarIconSize,
211+
attribute: Attribute.font,
212+
controller: controller,
213+
items: [
214+
for (MapEntry<String, String> fontFamily in fontFamilies.entries)
215+
PopupMenuItem<String>(
216+
key: ValueKey(fontFamily.key),
217+
value: fontFamily.value,
218+
child: Text(fontFamily.key.toString(),
219+
style: TextStyle(
220+
color:
221+
fontFamily.value == 'Clear' ? Colors.red : null)),
222+
),
223+
],
224+
onSelected: (newFont) {
225+
controller.formatSelection(Attribute.fromKeyValue(
226+
'font', newFont == 'Clear' ? null : newFont));
227+
},
228+
rawItemsMap: fontFamilies,
229+
),
192230
if (showFontSize)
193231
QuillFontSizeButton(
194232
iconTheme: iconTheme,

0 commit comments

Comments
 (0)