singerdmx / flutter-quill

Rich text editor for Flutter
https://pub.dev/packages/flutter_quill
MIT License
2.6k stars 840 forks source link

Clarification Needed on Custom Icon Support for Unordered Lists (LeadingBlockBuilder) #2168

Closed Gabianne01 closed 2 months ago

Gabianne01 commented 2 months ago

Is there an existing issue for this?

The question

I have been exploring the new LeadingBlockBuilder feature for customizing the leading icons in unordered lists, and I’ve encountered some challenges. The goal is to apply different icons to unordered list items, allowing each list block within a document to have its own unique icon as seen in issue 1611. This new feature claims to do that, but based on the comments, I'm unsure whether the feature fully supports this use case or if there's a workaround or future plans to enhance it.

As of now, it seems that the current implementation does not persist these custom icons in the document's Delta format, or I could not figure it out.

Currently, when a custom icon is selected and applied, it is correctly displayed within the editor. However, upon saving and reloading the document, the custom icons revert to the default, because I can't figure out how to store the icon choice in the document's Delta. This is particularly limiting as it prevents the icons from being different in each block or, at a minimum, from being retained uniquely across different documents.

Any help or suggestions would be greatly appreciated!


Widget? customLeadingBuilder(quill.Node node, quill.LeadingConfigurations config) {  
  if (config.attribute == quill.Attribute.ul) {  
    final customIconAttr = config.attrs['custom_icon'];
    if (customIconAttr != null) {
      final iconData = IconData(
        int.parse(customIconAttr.value),
        fontFamily: 'MaterialIcons', 
      );
      return Icon(iconData, size: config.style?.fontSize ?? 14);
    }
    return Icon(Icons.star, size: config.style?.fontSize ?? 14); // Fallback icon
  }
  return null;
}
Gabianne01 commented 2 months ago

Never mind, figured it out, by using custom attributes 😳.