diff --git a/lib/core/graph.dart b/lib/core/graph.dart index 907adc1f..9e3e97f0 100644 --- a/lib/core/graph.dart +++ b/lib/core/graph.dart @@ -174,8 +174,7 @@ class Graph extends ChangeNotifier { bool shouldStop = _updateGraphPositions(this); // print("shouldStop $shouldStop"); if (shouldStop) { - layoutTimer.cancel(); - layoutTimer = null; + stopLayout(); } }); @@ -187,6 +186,11 @@ class Graph extends ChangeNotifier { } });*/ } + + void stopLayout() { + layoutTimer.cancel(); + layoutTimer = null; + } } class GraphNodeLayout { diff --git a/lib/screens/graph_view.dart b/lib/screens/graph_view.dart index 1460a7ff..b350689a 100644 --- a/lib/screens/graph_view.dart +++ b/lib/screens/graph_view.dart @@ -20,15 +20,29 @@ class _GraphViewScreenState extends State { var rootFolder = Provider.of(context); setState(() { graph = Graph.fromFolder(rootFolder); - graph.addListener(() { - setState(() {}); - }); + graph.addListener(_setState); }); return Container(width: 2500, height: 2500); } return SafeArea(child: GraphView(graph)); } + + @override + void dispose() { + if (graph != null) { + graph.stopLayout(); + graph.removeListener(_setState); + } + + super.dispose(); + } + + void _setState() { + if (!mounted) return; + + setState(() {}); + } } class GraphView extends StatefulWidget {