Open Amir-P opened 2 years ago
There is defaultFleatherEmbedBuilder
that can be used as a fallback.
Widget _embedBuilder(BuildContext context, EmbedNode node) {
if (node.value.type == 'icon') {
final data = node.value.data;
return Icon(
IconData(int.parse(data['codePoint']), fontFamily: data['fontFamily']),
color: Color(int.parse(data['color'])),
size: 18,
);
}
defaultFleatherEmbedBuilder(context, node);
}
IMO current API already works really well and supports the fallback scenario that you are optimizing. One possible addition to defaultFleatherEmbedBuilder
could be to return Widget?
if it encounters an unknown type.
There are a few issues with the current embed builder API:
Suppose that I have an embed type of icon. My
embedBuilder
would be this if I want to support built-in embeds (currently we only have horizontal rule) too.Proposal: Instead of
Widget Function(BuildContext context, EmbedNode node)
as embed builder, we can have aMap<String, Widget Function(BuildContext context, EmbedNode node)>
where the key isEmbedNode.EmbeddableObject.type
. This way we can easily merge providedMap
with a default internalMap
inside editor and there is no need to rewrite built-in embed builders. It's more flexible than the current API.Previous example can be written to this:
Cons: Using current API we are able to return a default widget in case embed is not supported. With this change we can have a default embed builder too, which will be called if the
Map
does not containEmbedNode.EmbeddableObject.type
.