mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
GraphView: Dispose the Graph correctly
This commit is contained in:
@ -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 {
|
||||
|
@ -20,15 +20,29 @@ class _GraphViewScreenState extends State<GraphViewScreen> {
|
||||
var rootFolder = Provider.of<NotesFolderFS>(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 {
|
||||
|
Reference in New Issue
Block a user