Skip to content

Commit

Permalink
Support font family selection
Browse files Browse the repository at this point in the history
  • Loading branch information
singerdmx committed Jul 22, 2022
1 parent 6a462ee commit 71d06f6
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 4 deletions.
23 changes: 23 additions & 0 deletions lib/src/translations/toolbar.i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'en_us': {
'Paste a link': 'Paste a link',
Expand All @@ -52,6 +53,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'ar': {
'Paste a link': 'نسخ الرابط',
Expand All @@ -77,6 +79,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'da': {
'Paste a link': 'Indsæt link',
Expand All @@ -102,6 +105,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'de': {
'Paste a link': 'Link hinzufügen',
Expand All @@ -128,6 +132,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'fr': {
'Paste a link': 'Coller un lien',
Expand All @@ -153,6 +158,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'zh_CN': {
'Paste a link': '粘贴链接',
Expand All @@ -178,6 +184,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'ko': {
'Paste a link': '링크를 붙여넣어 주세요.',
Expand All @@ -202,6 +209,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'ru': {
'Paste a link': 'Вставить ссылку',
Expand All @@ -227,6 +235,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'es': {
'Paste a link': 'Pega un enlace',
Expand All @@ -253,6 +262,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'tr': {
'Paste a link': 'Bağlantıyı Yapıştır',
Expand All @@ -278,6 +288,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'uk': {
'Paste a link': 'Вставити посилання',
Expand All @@ -303,6 +314,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'pt': {
'Paste a link': 'Colar um link',
Expand All @@ -329,6 +341,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'pl': {
'Paste a link': 'Wklej link',
Expand All @@ -355,6 +368,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'vi': {
'Paste a link': 'Chèn liên kết',
Expand All @@ -381,6 +395,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'ur': {
'Paste a link': 'لنک پیسٹ کریں',
Expand All @@ -406,6 +421,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'id': {
'Paste a link': 'Tempel tautan',
Expand All @@ -431,6 +447,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'no': {
'Paste a link': 'Lim inn lenke',
Expand All @@ -456,6 +473,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'fa': {
'Paste a link': 'جایگذاری لینک',
Expand All @@ -481,6 +499,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'hi': {
'Paste a link': 'लिंक पेस्ट करें',
Expand All @@ -506,6 +525,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'nl': {
'Paste a link': 'Plak een link',
Expand All @@ -531,6 +551,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'zh_HK': {
'Paste a link': '貼上連結',
Expand All @@ -556,6 +577,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
'sr': {
'Paste a link': 'Nalepi vezu',
Expand All @@ -581,6 +603,7 @@ extension Localization on String {
'Large': 'Large',
'Huge': 'Huge',
'Clear': 'Clear',
'Font': 'Font',
},
};

Expand Down
40 changes: 39 additions & 1 deletion lib/src/widgets/toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'toolbar/image_button.dart';
import 'toolbar/image_video_utils.dart';
import 'toolbar/indent_button.dart';
import 'toolbar/link_style_button.dart';
import 'toolbar/quill_font_family_button.dart';
import 'toolbar/quill_font_size_button.dart';
import 'toolbar/quill_icon_button.dart';
import 'toolbar/select_alignment_button.dart';
Expand Down Expand Up @@ -78,6 +79,7 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
double toolbarSectionSpacing = 4,
WrapAlignment toolbarIconAlignment = WrapAlignment.center,
bool showDividers = true,
bool showFontFamily = true,
bool showFontSize = true,
bool showBoldButton = true,
bool showItalicButton = true,
Expand Down Expand Up @@ -119,6 +121,9 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
///Map of font sizes in string
Map<String, String>? fontSizeValues,

///Map of font families in string
Map<String, String>? fontFamilyValues,

///The theme to use for the icons in the toolbar, uses type [QuillIconTheme]
QuillIconTheme? iconTheme,

Expand All @@ -132,7 +137,8 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
Key? key,
}) {
final isButtonGroupShown = [
showFontSize ||
showFontFamily ||
showFontSize ||
showBoldButton ||
showItalicButton ||
showSmallButton ||
Expand Down Expand Up @@ -164,6 +170,15 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
'Clear'.i18n: '0'
};

//default font family values
final fontFamilies = fontFamilyValues ??
{
'Sans Serif': 'sans-serif',
'Serif': 'serif',
'Monospace': 'monospace',
'Clear': 'Clear'
};

return QuillToolbar(
key: key,
toolbarHeight: toolbarIconSize * 2,
Expand All @@ -189,6 +204,29 @@ class QuillToolbar extends StatelessWidget implements PreferredSizeWidget {
undo: false,
iconTheme: iconTheme,
),
if (showFontFamily)
QuillFontFamilyButton(
iconTheme: iconTheme,
iconSize: toolbarIconSize,
attribute: Attribute.font,
controller: controller,
items: [
for (MapEntry<String, String> fontFamily in fontFamilies.entries)
PopupMenuItem<String>(
key: ValueKey(fontFamily.key),
value: fontFamily.value,
child: Text(fontFamily.key.toString(),
style: TextStyle(
color:
fontFamily.value == 'Clear' ? Colors.red : null)),
),
],
onSelected: (newFont) {
controller.formatSelection(Attribute.fromKeyValue(
'font', newFont == 'Clear' ? null : newFont));
},
rawItemsMap: fontFamilies,
),
if (showFontSize)
QuillFontSizeButton(
iconTheme: iconTheme,
Expand Down
Loading

0 comments on commit 71d06f6

Please sign in to comment.