-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix wrong custom embed key #962
Conversation
@singerdmx I do not believe this fix is correct and I think it should be reverted. @theachoem What was the motivation for this change? In the original code, multiple custom builders can be provided, each corresponding to a custom type. After this change, a single builder has to be used to handle any type that isn't image, video or function. As all the nodes of custom builders are stored in the following form, it has to be decoded before the type can be compared with the builders.
|
I can see |
@Jon-Salmon could you submit a PR to revert it please? |
In block embed, we have Here is how I handle it. QuillEditor(
embedBuilders: [
QuillImageRenderer(),
QuillCustomRenderer(),
],
...
} import 'package:flutter/material.dart';
import 'package:flutter_quill/flutter_quill.dart' as quill;
import 'package:spooky/views/detail/quill_renderer/custom_date_block_renderer.dart';
import 'package:spooky/views/detail/quill_renderer/quill_unsupported_renderer.dart';
import 'package:spooky/views/detail/quill_renderer_helper/date_block_embed.dart';
class QuillCustomRenderer extends quill.EmbedBuilder {
@override
String get key => quill.BlockEmbed.customType;
@override
Widget build(BuildContext context, quill.QuillController controller, quill.Embed node, bool readOnly) {
quill.Embeddable block = node.value;
switch (block.type) {
case DateBlockEmbed.blockType:
return CustomDateBlockRenderer(
block: block as quill.CustomBlockEmbed,
readOnly: readOnly,
controller: controller,
);
default:
return const QuillUnsupportedRenderer();
}
}
} |
Data sample: [
{ "insert": "Journey!\n\n" },
{
"insert": {
"custom": "{\"date\":\"[{\\\"insert\\\":\\\"2022-09-28T07:51:20.595740\\\\n\\\"}]\"}"
}
},
{ "insert": "\n\n" },
{
"insert": {
"image": "~/Library/Developer/CoreSimulator/Devices/B5F51001-AAA2-4155-8033-62F671A24B66/data/Containers/Data/Application/42C2A551-F56E-4864-9535-8B91C0FA4F83/tmp/image_picker_6A40603C-3BD4-4F07-B7E1-8F72FD5072D9-10323-000001C059405FC3.jpg"
}
},
{ "insert": "\n" }
] |
@Jon-Salmon Your thought? |
@theachoem this doesn't break existing user data, instead your custom builder should look like: class QuillCustomRenderer extends quill.EmbedBuilder {
@override
String get key => DateBlockEmbed.blockType;
@override
Widget build(BuildContext context, quill.QuillController controller, quill.Embed node, bool readOnly) {
quill.Embeddable block = node.value;
return CustomDateBlockRenderer(
block: block as quill.CustomBlockEmbed,
readOnly: readOnly,
controller: controller,
);
}
} |
_node.value.type & node.value.type has different value in custom embed case which lead to error, should always use
node.value.type
.See how it error In
editor.dart
: