If you do removeAll(children)
in a component's onRemove
method it will assert with:
threw _AssertionError:<'package:flame/src/components/core/component.dart': Failed assertion: line 627 pos 7: 'child._parent != null': Trying to remove a component that doesn't belong to any parent>
To be able to remove all children in onRemove
so that one can do clean-up in there, if you add the children in onMount
for example.
testWithFlameGame(
'Remove all children in onRemove',
(game) async {
final component = _RemoveAllChildrenComponent();
component.addAll([Component(), Component()]);
game.add(component);
await game.ready();
expect(() => game.remove(component), returnsNormally);
expect(() => game.update(0), returnsNormally); // Here is the assertion.
},
);
class _RemoveAllChildrenComponent extends Component {
@override
void onRemove() {
removeAll(children);
}
}
main
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too