Fix Text direction default iconData and tooltip

pull/1506/head
Ellet 1 year ago
parent 0d38e8787d
commit 69c8b22e94
No known key found for this signature in database
GPG Key ID: C488CC70BBCEF0D1
  1. 13
      example/lib/pages/home_page.dart
  2. 108
      lib/src/widgets/toolbar/buttons/toggle_style.dart

@ -102,10 +102,14 @@ class _HomePageState extends State<HomePage> {
onPressed: () => showDialog( onPressed: () => showDialog(
context: context, context: context,
builder: (context) => AlertDialog( builder: (context) => AlertDialog(
content: Text(_controller.document.toPlainText([ content: Text(
...FlutterQuillEmbeds.editorBuilders(), _controller.document.toPlainText(
TimeStampEmbedBuilderWidget() [
])), ...FlutterQuillEmbeds.editorBuilders(),
TimeStampEmbedBuilderWidget()
],
),
),
), ),
), ),
icon: const Icon(Icons.text_fields_rounded), icon: const Icon(Icons.text_fields_rounded),
@ -286,6 +290,7 @@ class _HomePageState extends State<HomePage> {
if (_isDesktop()) { if (_isDesktop()) {
return QuillToolbar( return QuillToolbar(
configurations: QuillToolbarConfigurations( configurations: QuillToolbarConfigurations(
showDirection: true,
embedButtons: FlutterQuillEmbeds.toolbarButtons( embedButtons: FlutterQuillEmbeds.toolbarButtons(
imageButtonOptions: QuillToolbarImageButtonOptions( imageButtonOptions: QuillToolbarImageButtonOptions(
onImagePickCallback: _onImagePickCallback, onImagePickCallback: _onImagePickCallback,

@ -78,36 +78,36 @@ class QuillToolbarToggleStyleButtonState
context.requireQuillToolbarBaseButtonOptions.iconTheme; context.requireQuillToolbarBaseButtonOptions.iconTheme;
} }
String? get _defaultTooltip { (String?, IconData) get _defaultTooltipAndIconData {
switch (widget.attribute.key) { switch (widget.attribute.key) {
case 'bold': case 'bold':
return 'Bold'.i18n; return ('Bold'.i18n, Icons.format_bold);
case 'script': case 'script':
if (widget.attribute.value == ScriptAttributes.sub.value) { if (widget.attribute.value == ScriptAttributes.sub.value) {
return 'Subscript'.i18n; return ('Subscript'.i18n, Icons.subscript);
} }
return 'Superscript'.i18n; return ('Superscript'.i18n, Icons.superscript);
case 'italic': case 'italic':
return 'Italic'.i18n; return ('Italic'.i18n, Icons.format_italic);
case 'small': case 'small':
return 'Small'.i18n; return ('Small'.i18n, Icons.format_size);
case 'underline': case 'underline':
return 'Underline'.i18n; return ('Underline'.i18n, Icons.format_underline);
case 'strike': case 'strike':
return 'Strike through'.i18n; return ('Strike through'.i18n, Icons.format_strikethrough);
case 'code': case 'code':
return 'Inline code'.i18n; return ('Inline code'.i18n, Icons.code);
case 'rtl': case 'direction':
return 'Text direction'.i18n; return ('Text direction'.i18n, Icons.format_textdirection_r_to_l);
case 'list': case 'list':
if (widget.attribute.value == 'bullet') { if (widget.attribute.value == 'bullet') {
return 'Bullet list'.i18n; return ('Bullet list'.i18n, Icons.format_list_bulleted);
} }
return 'Numbered list'.i18n; return ('Numbered list'.i18n, Icons.format_list_numbered);
case 'code-block': case 'code-block':
return 'Code block'.i18n; return ('Code block'.i18n, Icons.code);
case 'blockquote': case 'blockquote':
return 'Quote'.i18n; return ('Quote'.i18n, Icons.format_quote);
default: default:
throw ArgumentError( throw ArgumentError(
'Could not find the default tooltip for ' 'Could not find the default tooltip for '
@ -116,53 +116,53 @@ class QuillToolbarToggleStyleButtonState
} }
} }
// IconData get _defaultIconData {
// switch (widget.attribute.key) {
// case 'bold':
// return Icons.format_bold;
// case 'script':
// if (widget.attribute.value == ScriptAttributes.sub.value) {
// return Icons.subscript;
// }
// return Icons.superscript;
// case 'italic':
// return Icons.format_italic;
// case 'small':
// return Icons.format_size;
// case 'underline':
// return Icons.format_underline;
// case 'strike':
// return Icons.format_strikethrough;
// case 'code':
// return Icons.code;
// case 'rtl':
// return Icons.format_textdirection_r_to_l;
// case 'list':
// if (widget.attribute.value == 'bullet') {
// return Icons.format_list_bulleted;
// }
// return Icons.format_list_numbered;
// case 'code-block':
// return Icons.code;
// case 'blockquote':
// return Icons.format_quote;
// default:
// throw ArgumentError(
// 'Could not find the icon for ${widget.attribute.toString()}',
// );
// }
// }
String? get tooltip { String? get tooltip {
return options.tooltip ?? return options.tooltip ??
context.requireQuillToolbarBaseButtonOptions.tooltip ?? context.requireQuillToolbarBaseButtonOptions.tooltip ??
_defaultTooltip; _defaultTooltipAndIconData.$1;
}
IconData get _defaultIconData {
switch (widget.attribute.key) {
case 'bold':
return Icons.format_bold;
case 'script':
if (widget.attribute.value == ScriptAttributes.sub.value) {
return Icons.subscript;
}
return Icons.superscript;
case 'italic':
return Icons.format_italic;
case 'small':
return Icons.format_size;
case 'underline':
return Icons.format_underline;
case 'strike':
return Icons.format_strikethrough;
case 'code':
return Icons.code;
case 'rtl':
return Icons.format_textdirection_r_to_l;
case 'list':
if (widget.attribute.value == 'bullet') {
return Icons.format_list_bulleted;
}
return Icons.format_list_numbered;
case 'code-block':
return Icons.code;
case 'blockquote':
return Icons.format_quote;
default:
throw ArgumentError(
'Could not find the icon for ${widget.attribute.toString()}',
);
}
} }
IconData get iconData { IconData get iconData {
return options.iconData ?? return options.iconData ??
context.requireQuillToolbarBaseButtonOptions.iconData ?? context.requireQuillToolbarBaseButtonOptions.iconData ??
_defaultIconData; _defaultTooltipAndIconData.$2;
} }
void _onPressed() { void _onPressed() {

Loading…
Cancel
Save