Dispose render objects when owning element is unmounted. (#82883)
This commit is contained in:
@@ -455,7 +455,6 @@ class RenderSectorSlice extends RenderSectorWithChildren {
|
||||
}
|
||||
|
||||
class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChildMixin<RenderSector> {
|
||||
|
||||
RenderBoxToRenderSectorAdapter({ double innerRadius = 0.0, RenderSector? child })
|
||||
: _innerRadius = innerRadius {
|
||||
this.child = child;
|
||||
@@ -567,7 +566,6 @@ class RenderBoxToRenderSectorAdapter extends RenderBox with RenderObjectWithChil
|
||||
result.add(BoxHitTestEntry(this, position));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class RenderSolidColor extends RenderDecoratedSector {
|
||||
|
||||
@@ -90,6 +90,13 @@ class SectorAppState extends State<SectorApp> {
|
||||
});
|
||||
}
|
||||
|
||||
void recursivelyDisposeChildren(RenderObject parent) {
|
||||
parent.visitChildren((RenderObject child) {
|
||||
recursivelyDisposeChildren(child);
|
||||
child.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
Widget buildBody() {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
@@ -107,7 +114,12 @@ class SectorAppState extends State<SectorApp> {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
margin: const EdgeInsets.only(right: 10.0),
|
||||
child: WidgetToRenderBoxAdapter(renderBox: sectorAddIcon),
|
||||
child: WidgetToRenderBoxAdapter(
|
||||
renderBox: sectorAddIcon,
|
||||
onUnmount: () {
|
||||
recursivelyDisposeChildren(sectorAddIcon);
|
||||
},
|
||||
),
|
||||
),
|
||||
const Text('ADD SECTOR'),
|
||||
],
|
||||
@@ -122,7 +134,12 @@ class SectorAppState extends State<SectorApp> {
|
||||
Container(
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
margin: const EdgeInsets.only(right: 10.0),
|
||||
child: WidgetToRenderBoxAdapter(renderBox: sectorRemoveIcon),
|
||||
child: WidgetToRenderBoxAdapter(
|
||||
renderBox: sectorRemoveIcon,
|
||||
onUnmount: () {
|
||||
recursivelyDisposeChildren(sectorRemoveIcon);
|
||||
},
|
||||
),
|
||||
),
|
||||
const Text('REMOVE SECTOR'),
|
||||
],
|
||||
@@ -142,6 +159,9 @@ class SectorAppState extends State<SectorApp> {
|
||||
child: WidgetToRenderBoxAdapter(
|
||||
renderBox: sectors,
|
||||
onBuild: doUpdates,
|
||||
onUnmount: () {
|
||||
recursivelyDisposeChildren(sectors);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user