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);
|
bool shouldStop = _updateGraphPositions(this);
|
||||||
// print("shouldStop $shouldStop");
|
// print("shouldStop $shouldStop");
|
||||||
if (shouldStop) {
|
if (shouldStop) {
|
||||||
layoutTimer.cancel();
|
stopLayout();
|
||||||
layoutTimer = null;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -187,6 +186,11 @@ class Graph extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
});*/
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void stopLayout() {
|
||||||
|
layoutTimer.cancel();
|
||||||
|
layoutTimer = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GraphNodeLayout {
|
class GraphNodeLayout {
|
||||||
|
@ -20,15 +20,29 @@ class _GraphViewScreenState extends State<GraphViewScreen> {
|
|||||||
var rootFolder = Provider.of<NotesFolderFS>(context);
|
var rootFolder = Provider.of<NotesFolderFS>(context);
|
||||||
setState(() {
|
setState(() {
|
||||||
graph = Graph.fromFolder(rootFolder);
|
graph = Graph.fromFolder(rootFolder);
|
||||||
graph.addListener(() {
|
graph.addListener(_setState);
|
||||||
setState(() {});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return Container(width: 2500, height: 2500);
|
return Container(width: 2500, height: 2500);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SafeArea(child: GraphView(graph));
|
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 {
|
class GraphView extends StatefulWidget {
|
||||||
|
Reference in New Issue
Block a user