我想删除我的类中的渲染框
class RenderDynamicTimeline extends RenderBox
with
ContainerRenderObjectMixin<RenderBox, DynamicTimelineParentData>,
RenderBoxContainerDefaultsMixin<RenderBox, DynamicTimelineParentData> {
///default Code
}
下面是使用dropChild()
的代码:
void deleteChildBykey(Key? childKey) {
// Find the child with the matching key
for (final child in getChildrenAsList()) {
final dynamicTimelineParentData = child.parentData as DynamicTimelineParentData;
if (dynamicTimelineParentData.key == childKey) {
dynamicTimelineParentData.previousSibling = null;
dynamicTimelineParentData.nextSibling = null;
dropChild(child);
break;
}
}
}
问题是,我在layout函数中从RenderDynamicTimeline
得到了一个Null check operator used on a null value error
,正如我通过调试看到的那样,子对象已经在RenderDynamicTimeline中作为子对象存在,但是parentData
被删除了。子项标记为NEEDS-PAINT DETACHED
如何从RenderDynamicTimeline
类中删除完整的子类?
1条答案
按热度按时间u3r8eeie1#
正如@pskink提到的,
remove
是解决方案: