Refactor function _buildCustomBlockEmbed

pull/963/head
X Code 3 years ago
parent 8c387f7918
commit 24d9cdc6a8
  1. 54
      lib/src/widgets/editor.dart

@ -480,31 +480,8 @@ class QuillEditorState extends State<QuillEditor>
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<QuillEditor>
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<EditorState> get editableTextKey => _editorKey;

Loading…
Cancel
Save