How to remove tags or classes from the HTML inside a factory #840
-
We are currently building in a collapsible widget factory. However, the current problem is that the initial state can also be hidden. This is solved on the web via Is there any way with a factory to remove certain classes or tags? We would like to get to the class, read whether the content should be displayed, and then remove the display none from the tree. Our current widget factory: mixin TMXCollapseFactory on WidgetFactory {
@override
void parse(BuildMetadata meta) {
if (meta.element.classes.contains('accordion-section')) {
Widget? header;
meta.register(
BuildOp(
onChild: (collapseMeta) {
// ignore grand children etc.
if (collapseMeta.element.parent != meta.element) {
return;
}
if (collapseMeta.element.classes.contains('accordion-header')) {
collapseMeta.register(
BuildOp(
onWidgets: (_, widgets) {
header = AbsorbPointer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: widgets.toList(),
),
);
return [];
},
),
);
}
},
onWidgets: (_, widgets) => [
TMXCollapsible(
header: header ?? const SizedBox.shrink(),
hideCollapseIcon: true,
initialCollapsed: true,
children: widgets.toList(),
),
],
),
);
}
return super.parse(meta);
}
} Example html: <div class="accordion">
<li class="accordion-section">
<div class="accordion-header">
<a target="_self" class="btn">Show or hide content</a>
</div>
<div class="accordion-content" style="display: none;">
<p>Content</p>
</div>
</li>
</ul> Current result Without display none |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You should be able to override |
Beta Was this translation helpful? Give feedback.
You should be able to override
display: block
to render the element as usual. Then hide it in your custom widget later.