-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
150 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:visual_graphs/components/edge_component.dart'; | ||
|
||
class EdgeInfoBox extends StatefulWidget { | ||
final EdgeComponent edgeComponent; | ||
const EdgeInfoBox({super.key, required this.edgeComponent}); | ||
|
||
@override | ||
State<EdgeInfoBox> createState() => _EdgeInfoBoxState(); | ||
} | ||
|
||
class _EdgeInfoBoxState extends State<EdgeInfoBox> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return AlertDialog.adaptive( | ||
title: Text( | ||
"Edge: Node ${widget.edgeComponent.edge.from.label} ${widget.edgeComponent.edge.isDirected ? "to" : "&"} Node ${widget.edgeComponent.edge.to.label}"), | ||
content: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Text("ID: ${widget.edgeComponent.edge.id}"), | ||
TextField( | ||
decoration: const InputDecoration( | ||
labelText: "Weight", | ||
), | ||
keyboardType: TextInputType.number, | ||
controller: TextEditingController( | ||
text: widget.edgeComponent.edge.weight.toString()), | ||
focusNode: FocusNode()..requestFocus(), | ||
onChanged: (value) { | ||
if (value.isEmpty) { | ||
widget.edgeComponent.edge.weight = 0; | ||
} | ||
try { | ||
widget.edgeComponent.edge.weight = int.parse(value); | ||
} catch (e) { | ||
return; | ||
} | ||
}, | ||
inputFormatters: [ | ||
FilteringTextInputFormatter.allow(RegExp(r'[0-9\-]')), | ||
], | ||
), | ||
CheckboxListTile( | ||
title: const Text("Directed"), | ||
value: widget.edgeComponent.edge.isDirected, | ||
onChanged: (value) => setState(() { | ||
widget.edgeComponent.gameRef.graph | ||
.removeEdge(widget.edgeComponent.edge); | ||
widget.edgeComponent.edge.isDirected = value!; | ||
widget.edgeComponent.gameRef.graph | ||
.addEdge(widget.edgeComponent.edge); | ||
}), | ||
), | ||
if (widget.edgeComponent.edge.isDirected) | ||
ElevatedButton.icon( | ||
onPressed: () { | ||
widget.edgeComponent.gameRef.graph | ||
.removeEdge(widget.edgeComponent.edge); | ||
|
||
// swap the vertices | ||
var temp = widget.edgeComponent.edge.from; | ||
widget.edgeComponent.edge.from = widget.edgeComponent.edge.to; | ||
widget.edgeComponent.edge.to = temp; | ||
|
||
widget.edgeComponent.gameRef.graph | ||
.addEdge(widget.edgeComponent.edge); | ||
setState(() {}); | ||
}, | ||
label: const Text("Reverse"), | ||
icon: const Icon(Icons.swap_horiz_outlined), | ||
), | ||
const SizedBox(height: 10), | ||
Row( | ||
mainAxisSize: MainAxisSize.max, | ||
mainAxisAlignment: MainAxisAlignment.end, | ||
children: [ | ||
FilledButton( | ||
child: const Text("Done"), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
], | ||
) | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:visual_graphs/components/vertex_component.dart'; | ||
|
||
class VertexInfoBox extends StatefulWidget { | ||
final VertexComponent vertexComponent; | ||
const VertexInfoBox({super.key, required this.vertexComponent}); | ||
|
||
@override | ||
State<VertexInfoBox> createState() => _VertexInfoBoxState(); | ||
} | ||
|
||
class _VertexInfoBoxState extends State<VertexInfoBox> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return AlertDialog.adaptive( | ||
title: Text("Node ${widget.vertexComponent.vertex.label}"), | ||
content: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Text("ID: ${widget.vertexComponent.vertex.id}"), | ||
TextField( | ||
decoration: const InputDecoration( | ||
labelText: "Label", | ||
), | ||
controller: TextEditingController( | ||
text: widget.vertexComponent.vertex.label), | ||
focusNode: FocusNode()..requestFocus(), | ||
onChanged: (value) { | ||
widget.vertexComponent.vertex.label = value; | ||
}, | ||
), | ||
const SizedBox(height: 10), | ||
Row( | ||
mainAxisSize: MainAxisSize.max, | ||
mainAxisAlignment: MainAxisAlignment.end, | ||
children: [ | ||
FilledButton( | ||
child: const Text("Done"), | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
), | ||
], | ||
) | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters