mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
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:
@ -4,8 +4,6 @@ import 'dart:math';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
|
||||||
import 'package:touchable/touchable.dart';
|
|
||||||
|
|
||||||
class MyExampleWidget extends StatefulWidget {
|
class MyExampleWidget extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
_MyExampleWidgetState createState() => _MyExampleWidgetState();
|
_MyExampleWidgetState createState() => _MyExampleWidgetState();
|
||||||
@ -56,65 +54,22 @@ class _MyExampleWidgetState extends State<MyExampleWidget> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MyPainter extends CustomPainter {
|
class MyPainter extends CustomPainter {
|
||||||
final BuildContext context;
|
|
||||||
final Graph graph;
|
final Graph graph;
|
||||||
|
|
||||||
MyPainter(this.context, this.graph) : super(repaint: graph);
|
MyPainter(this.graph) : super(repaint: graph);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void paint(Canvas canvas, Size size) {
|
void paint(Canvas canvas, Size size) {
|
||||||
var myCanvas = TouchyCanvas(context, canvas);
|
|
||||||
|
|
||||||
// Draw all the edges
|
// Draw all the edges
|
||||||
for (var edge in graph.edges) {
|
for (var edge in graph.edges) {
|
||||||
myCanvas.drawLine(
|
canvas.drawLine(
|
||||||
Offset(edge.a.x, edge.a.y),
|
Offset(edge.a.x, edge.a.y),
|
||||||
Offset(edge.b.x, edge.b.y),
|
Offset(edge.b.x, edge.b.y),
|
||||||
Paint()
|
Paint()
|
||||||
..color = Colors.grey
|
..color = Colors.grey
|
||||||
..strokeWidth = 2.5,
|
..strokeWidth = 2.5,
|
||||||
onPanUpdate: (detail) {
|
/*onPanUpdate: (detail) {
|
||||||
print('Edge ${edge.a.label} -> ${edge.b.label} Swiped');
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var children = <Widget>[];
|
var children = <Widget>[];
|
||||||
|
|
||||||
|
children.add(CustomPaint(painter: MyPainter(widget.graph)));
|
||||||
|
|
||||||
for (var node in widget.graph.nodes) {
|
for (var node in widget.graph.nodes) {
|
||||||
var w = Positioned(
|
var w = Positioned(
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
|
@ -924,13 +924,6 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.9.5+1"
|
version: "1.9.5+1"
|
||||||
touchable:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: touchable
|
|
||||||
url: "https://pub.dartlang.org"
|
|
||||||
source: hosted
|
|
||||||
version: "0.1.7"
|
|
||||||
tuple:
|
tuple:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -56,7 +56,6 @@ dependencies:
|
|||||||
receive_sharing_intent: ^1.4.0+2
|
receive_sharing_intent: ^1.4.0+2
|
||||||
in_app_purchase: ^0.3.4+1
|
in_app_purchase: ^0.3.4+1
|
||||||
flutter_plugin_android_lifecycle: ^1.0.8 # for fixing the build
|
flutter_plugin_android_lifecycle: ^1.0.8 # for fixing the build
|
||||||
touchable: ^0.1.7
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_launcher_icons: "^0.7.2"
|
flutter_launcher_icons: "^0.7.2"
|
||||||
|
Reference in New Issue
Block a user