From 24d9cdc6a893fb2822fdc1b17526ab834a1a5c79 Mon Sep 17 00:00:00 2001 From: X Code Date: Tue, 27 Sep 2022 06:43:43 -0700 Subject: [PATCH] Refactor function _buildCustomBlockEmbed --- lib/src/widgets/editor.dart | 54 ++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/lib/src/widgets/editor.dart b/lib/src/widgets/editor.dart index ef564491..38279fa7 100644 --- a/lib/src/widgets/editor.dart +++ b/lib/src/widgets/editor.dart @@ -480,31 +480,8 @@ class QuillEditorState extends State controller, node, readOnly, - ) { - final builders = widget.embedBuilders; - - if (builders != null) { - var _node = node; - final type = node.value.type; - - // Creates correct node for custom embed - if (type == BlockEmbed.customType) { - _node = Embed(CustomBlockEmbed.fromJsonString(node.value.data)); - } - - for (final builder in builders) { - if (builder.key == type) { - return builder.build(context, controller, _node, readOnly); - } - } - } - - throw UnimplementedError( - 'Embeddable type "${node.value.type}" is not supported by supplied ' - 'embed builders. You must pass your own builder function to ' - 'embedBuilders property of QuillEditor or QuillField widgets.', - ); - }, + ) => + _buildCustomBlockEmbed(node, context, controller, readOnly), linkActionPickerDelegate: widget.linkActionPickerDelegate, customStyleBuilder: widget.customStyleBuilder, floatingCursorDisabled: widget.floatingCursorDisabled, @@ -538,6 +515,33 @@ class QuillEditorState extends State return editor; } + Widget _buildCustomBlockEmbed(Embed node, BuildContext context, + QuillController controller, bool readOnly) { + final builders = widget.embedBuilders; + + if (builders != null) { + var _node = node; + final type = node.value.type; + + // Creates correct node for custom embed + if (type == BlockEmbed.customType) { + _node = Embed(CustomBlockEmbed.fromJsonString(node.value.data)); + } + + for (final builder in builders) { + if (builder.key == type) { + return builder.build(context, controller, _node, readOnly); + } + } + } + + throw UnimplementedError( + 'Embeddable type "${node.value.type}" is not supported by supplied ' + 'embed builders. You must pass your own builder function to ' + 'embedBuilders property of QuillEditor or QuillField widgets.', + ); + } + @override GlobalKey get editableTextKey => _editorKey;