From 52b8d8c9efd7650776d8fb044f0ff019ba9911ce Mon Sep 17 00:00:00 2001 From: Mike Burton Date: Mon, 22 Jan 2024 18:37:57 -0800 Subject: [PATCH] Update GraphView.dart Fix for index out of range when changing graph object between renders --- lib/GraphView.dart | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/GraphView.dart b/lib/GraphView.dart index dea5abe..c56b3c8 100644 --- a/lib/GraphView.dart +++ b/lib/GraphView.dart @@ -239,14 +239,11 @@ class _GraphViewAnimated extends StatefulWidget { final Graph graph; final Algorithm algorithm; final Paint? paint; - final nodes = []; + final NodeWidgetBuilder builder; final stepMilis = 25; _GraphViewAnimated( - {Key? key, required this.graph, required this.algorithm, this.paint, required NodeWidgetBuilder builder}) { - graph.nodes.forEach((node) { - nodes.add(node.data ?? builder(node)); - }); + {Key? key, required this.graph, required this.algorithm, this.paint, required this.builder}) { } @override @@ -296,7 +293,7 @@ class _GraphViewAnimatedState extends State<_GraphViewAnimated> { ...List.generate(graph.nodeCount(), (index) { return Positioned( child: GestureDetector( - child: widget.nodes[index], + child: graph.nodes[index].data ?? widget.builder(graph.nodes[index]), onPanUpdate: (details) { graph.getNodeAtPosition(index).position += details.delta; update();