GraphView: Draw the edges with a normal canvas

We no longer need the touchy canvas as the nodes are proper Widgets
which makes everything so much easier.
This commit is contained in:
Vishesh Handa
2020-08-18 13:17:57 +02:00
parent 06275ae206
commit f2e61d3efd
3 changed files with 6 additions and 56 deletions

View File

@ -4,8 +4,6 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:touchable/touchable.dart';
class MyExampleWidget extends StatefulWidget {
@override
_MyExampleWidgetState createState() => _MyExampleWidgetState();
@ -56,65 +54,22 @@ class _MyExampleWidgetState extends State<MyExampleWidget> {
}
class MyPainter extends CustomPainter {
final BuildContext context;
final Graph graph;
MyPainter(this.context, this.graph) : super(repaint: graph);
MyPainter(this.graph) : super(repaint: graph);
@override
void paint(Canvas canvas, Size size) {
var myCanvas = TouchyCanvas(context, canvas);
// Draw all the edges
for (var edge in graph.edges) {
myCanvas.drawLine(
canvas.drawLine(
Offset(edge.a.x, edge.a.y),
Offset(edge.b.x, edge.b.y),
Paint()
..color = Colors.grey
..strokeWidth = 2.5,
onPanUpdate: (detail) {
/*onPanUpdate: (detail) {
print('Edge ${edge.a.label} -> ${edge.b.label} Swiped');
},
);
}
// Draw all the nodes
for (var node in graph.nodes) {
myCanvas.drawCircle(
Offset(node.x, node.y),
20,
Paint()..color = Colors.orange,
onPanStart: (tapdetail) {
node.pressed = true;
print('$node Pan start - $tapdetail');
node.x = tapdetail.localPosition.dx;
node.y = tapdetail.localPosition.dy;
graph.notify();
},
onPanDown: (tapdetail) {
node.pressed = false;
print('$node PanEnd - $tapdetail');
node.x = tapdetail.localPosition.dx;
node.y = tapdetail.localPosition.dy;
graph.notify();
},
onPanUpdate: (tapdetail) {
print('$node PanUpdate - $tapdetail');
node.x = tapdetail.localPosition.dx;
node.y = tapdetail.localPosition.dy;
graph.notify();
},
/*
onTapDown: (details) {
print("$node onTapDown - $details");
},
onTapUp: (details) {
print("$node onTapUp - $details");
},*/
);
}
@ -528,6 +483,9 @@ class _GraphStackViewState extends State<GraphStackView> {
@override
Widget build(BuildContext context) {
var children = <Widget>[];
children.add(CustomPaint(painter: MyPainter(widget.graph)));
for (var node in widget.graph.nodes) {
var w = Positioned(
child: GestureDetector(

View File

@ -924,13 +924,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.5+1"
touchable:
dependency: "direct main"
description:
name: touchable
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.7"
tuple:
dependency: transitive
description:

View File

@ -56,7 +56,6 @@ dependencies:
receive_sharing_intent: ^1.4.0+2
in_app_purchase: ^0.3.4+1
flutter_plugin_android_lifecycle: ^1.0.8 # for fixing the build
touchable: ^0.1.7
dev_dependencies:
flutter_launcher_icons: "^0.7.2"