Загрузил(а) файлы в 'flutter/lib/pages'

This commit is contained in:
Морозов Андрей 2021-11-11 08:11:35 +00:00
parent e1bca55bcf
commit 8fea8c95fc
1 changed files with 154 additions and 122 deletions

View File

@ -1,5 +1,5 @@
import 'package:graphs/src/graph.dart';
import 'package:graphs/curve_painter.dart';
import 'package:graphs/src/curve_painter.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
@ -11,7 +11,7 @@ Graphs getGraph() {
d.add(Dot.fromTwoLists("3", [1, 2], [1, 2]));
//d.add(Dot.fromTwoLists("Name1", [], []));
//d.add(Dot.fromTwoLists("Name2", [], []));
return Graphs.fromList("Имя", d, true, true);
return Graphs.fromList("Имя графа", d, true, true);
}
class DrawingPage extends StatefulWidget {
@ -24,31 +24,37 @@ class DrawingPage extends StatefulWidget {
class _DrawingPageState extends State<DrawingPage> {
double screenSize = 0;
Graphs graphData = getGraph();
List<int>? bfsPath;
List<int?>? intListPath;
List<bool>? dfsAccessTable;
//List<int?>? dijkstraTable;
String op = Operations.none;
int? startDot;
int? endDot;
String? dropdownValue1;
String? dropdownValue2;
String currOp = "";
final _textNameController = TextEditingController();
final _textNumbController = TextEditingController();
final _textDestController = TextEditingController();
final _textLnthController = TextEditingController();
final _textGrNmController = TextEditingController();
void clearInputData() {
setState(() {
_textDestController.clear();
_textNumbController.clear();
_textLnthController.clear();
_textNameController.clear();
dropdownValue1 = null;
dropdownValue2 = null;
/*startDot = null;
bfsPath = null;
});
}
void clearDropDownVals() {
setState(() {
startDot = null;
intListPath = null;
dfsAccessTable = null;
endDot = null;*/
endDot = null;
currOp = "";
op = Operations.none;
});
}
@ -94,11 +100,11 @@ class _DrawingPageState extends State<DrawingPage> {
// ***addSpace***
// *************inputs*************
Container createInputBox(String text, double wid, IconData? icon,
Container createInputBox(String text, double width, IconData? icon,
TextEditingController? controller) {
if (icon == null) {
return Container(
width: wid,
width: width,
height: 40,
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 5),
child: TextField(
@ -118,7 +124,7 @@ class _DrawingPageState extends State<DrawingPage> {
));
}
return Container(
width: wid,
width: width,
height: 40,
margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 5),
child: TextField(
@ -209,45 +215,44 @@ class _DrawingPageState extends State<DrawingPage> {
//*********ButtonsFunctions*********
void addDotPushed() {
setState(() {
if (_textNameController.text == "") {
showPopUp("Error", "No name in \"Dot name\" box");
} else {
clearDropDownVals();
if (_textNameController.text == "") {
showPopUp("Error", "No name in \"Dot name\" box");
} else {
setState(() {
String? res = graphData.addIsolated(_textNameController.text);
if (res != null) {
showPopUp("Error", res);
}
}
clearInputData();
});
});
}
clearInputData();
}
void addPathPushed() {
setState(() {
if (dropdownValue1 == null) {
showPopUp("Error", "Select output dot");
} else if (dropdownValue2 == null) {
showPopUp("Error", "select input dot");
} else if (_textLnthController.text == "" &&
graphData.getUseLengthBool()) {
showPopUp("Error", "No length in \"Input length\" box");
clearDropDownVals();
if (dropdownValue1 == null) {
showPopUp("Error", "Select output dot");
} else if (dropdownValue2 == null) {
showPopUp("Error", "select input dot");
} else if (_textLnthController.text == "" && graphData.getUseLengthBool()) {
showPopUp("Error", "No length in \"Input length\" box");
} else {
int? from = int.parse(dropdownValue1!);
int? to = int.parse(dropdownValue2!);
int? len = int.tryParse(_textLnthController.text);
if (len == null && graphData.getUseLengthBool()) {
showPopUp("Error",
"Can't parse input.\nInts only allowed in \"Dot number\", \"Destination number\" and \"Input length\"");
} else {
int? from = int.parse(dropdownValue1!);
int? to = int.parse(dropdownValue2!);
int? len = int.tryParse(_textLnthController.text);
if (len == null && graphData.getUseLengthBool()) {
showPopUp("Error",
"Can't parse input.\nInts only allowed in \"Dot number\", \"Destination number\" and \"Input length\"");
} else {
len ??= 0;
String? res = graphData.addPath(from, to, len);
if (res != null) {
showPopUp("Error", res);
}
}
len ??= 0;
setState(() {
String? res = graphData.addPath(from, to, len!);
if (res != null) showPopUp("Error", res);
});
}
clearInputData();
});
}
clearInputData();
}
void changeOriented() {
@ -265,55 +270,64 @@ class _DrawingPageState extends State<DrawingPage> {
}
void delPathPushed() {
setState(() {
if (_textNumbController.text == "") {
showPopUp("Error", "No number in \"Dot number\" box");
} else if (_textDestController.text == "") {
showPopUp("Error", "No name in \"Dot name\" box");
clearDropDownVals();
if (dropdownValue1 == null) {
showPopUp("Error", "No number in \"Dot number\" box");
} else if (dropdownValue2 == null) {
showPopUp("Error", "No name in \"Dot name\" box");
} else {
int? from = int.tryParse(dropdownValue1!);
int? to = int.tryParse(dropdownValue2!);
if (from == null || to == null) {
showPopUp("Error",
"Can't parse input.\nInts only allowed in \"Dot number\" and \"Destination number\"");
} else {
int? from = int.tryParse(_textNumbController.text);
int? to = int.tryParse(_textDestController.text);
if (from == null || to == null) {
showPopUp("Error",
"Can't parse input.\nInts only allowed in \"Dot number\" and \"Destination number\"");
} else {
setState(() {
String? res = graphData.delPath(from, to);
if (res != null) {
showPopUp("Error", res);
}
}
});
}
clearInputData();
});
}
clearInputData();
}
void delDotPushed() {
setState(() {
if (dropdownValue1 != null) {
graphData.delDot(int.parse(dropdownValue1!));
} else {
showPopUp("Error", "Nothing in input");
}
clearInputData();
});
if (dropdownValue1 != null) {
setState(() {
String? res = graphData.delDot(int.parse(dropdownValue1!));
if (res != null) {
showPopUp("Error", res);
}
});
} else {
showPopUp("Error", "Nothing in input");
}
clearDropDownVals();
clearInputData();
}
void fileOpener() async {
FilePickerResult? result =
await FilePicker.platform.pickFiles(allowedExtensions: ["txt"]);
setState(() {
if (result != null) {
if (!result.files.single.path!.endsWith(".txt")) {
showPopUp("Error", "Can open only \".txt\" files");
} else {
if (result != null) {
if (!result.files.single.path!.endsWith(".txt")) {
showPopUp("Error", "Can open only \".txt\" files");
} else {
setState(() {
String? res =
graphData.replaceDataFromFile(result.files.single.path!);
if (res != null) showPopUp("Error", res);
}
} else {
showPopUp("Error", "No file selected");
});
}
});
} else {
showPopUp("Error", "No file selected");
}
clearDropDownVals();
clearInputData();
}
void fileSaver() async {
@ -329,50 +343,69 @@ class _DrawingPageState extends State<DrawingPage> {
}
graphData.printToFile(outputFile);
}
clearDropDownVals();
clearInputData();
}
void bfsPushed() {
setState(() {
bfsPath = null;
dfsAccessTable = null;
startDot = null;
endDot = null;
if (dropdownValue1 == null) {
showPopUp("Error", "No number in \"Dot number\" box");
} else if (dropdownValue2 == null) {
showPopUp("Error", "No number in \"Destination number\" box");
} else {
clearDropDownVals();
if (dropdownValue1 == null) {
showPopUp("Error", "No number in \"Dot number\" box");
} else if (dropdownValue2 == null) {
showPopUp("Error", "No number in \"Destination number\" box");
} else {
setState(() {
startDot = int.parse(dropdownValue1!);
endDot = int.parse(dropdownValue2!);
bfsPath = graphData.bfsPath(startDot!, endDot!);
if (bfsPath == null) {
showPopUp("Info", "There is no path");
}
print(bfsPath);
currOp = "OP: BFS from $startDot to $endDot";
op = Operations.bfs;
intListPath = graphData.bfsPath(startDot!, endDot!);
});
if (intListPath == null) {
showPopUp("Info", "There is no path");
}
});
//print(intListPath);
}
clearInputData();
}
void dfsPushed() {
setState(() {
bfsPath = null;
dfsAccessTable = null;
startDot = null;
endDot = null;
if (dropdownValue1 == null) {
showPopUp("Error", "No number in \"Dot number\" box");
} else {
clearDropDownVals();
if (dropdownValue1 == null) {
showPopUp("Error", "No number in \"Dot number\" box");
} else {
setState(() {
startDot = int.parse(dropdownValue1!);
op = Operations.dfs;
currOp = "OP: DFS from $startDot";
dfsAccessTable = graphData.dfsIterative(startDot!);
if (dfsAccessTable == null) {
showPopUp("Err", "report this error.");
}
print(dfsAccessTable);
});
if (dfsAccessTable == null) {
showPopUp("Err", "report this error.");
}
clearInputData();
});
//print(dfsAccessTable);
}
clearInputData();
}
void dijkstraPushed() {
clearDropDownVals();
if (dropdownValue1 == null) {
showPopUp("Error", "No number in \"Dot number\" box");
} else {
setState(() {
startDot = int.parse(dropdownValue1!);
currOp = "OP: DFS from $startDot";
op = Operations.dijkstra;
intListPath = graphData.dijkstra(startDot!);
});
if (intListPath == null) {
showPopUp("Err", "report this error.");
}
//print(intListPath);
}
clearInputData();
}
//*********ButtonsFunctions*********
@ -416,7 +449,7 @@ class _DrawingPageState extends State<DrawingPage> {
//createInputBox("Dot number", screenSize / 4 - 25, Icons.fiber_manual_record, _textNumbController),
addSpaceW(54),
dropList1(screenSize / 4 - 80),
addSpaceW(54),
addSpaceW(53),
createButton("\nDel path\n", delPathPushed),
addSpaceW(54),
dropList2(screenSize / 4 - 80),
@ -428,10 +461,7 @@ class _DrawingPageState extends State<DrawingPage> {
IconButton(
onPressed: () {
setState(() {
startDot = null;
endDot = null;
bfsPath = null;
dfsAccessTable = null;
clearDropDownVals();
graphData.flushData();
clearInputData();
});
@ -443,31 +473,33 @@ class _DrawingPageState extends State<DrawingPage> {
body: CustomPaint(
painter: CurvePainter(
graphData: graphData,
bfsPath: bfsPath,
intListPath: intListPath,
dfsAccessTable: dfsAccessTable,
start: startDot,
end: endDot),
end: endDot,
op: op),
child: Align(
alignment: Alignment.topRight,
child: ButtonBar(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
currOp,
style: const TextStyle(fontSize: 14, color: Colors.black),
),
createButton("Bfs", bfsPushed),
createButton("Dfs", dfsPushed),
createButton("Clear dfs or bfs", () {
setState(() {
bfsPath = null;
dfsAccessTable = null;
startDot = null;
endDot = null;
clearInputData();
});
createButton("Dijkstra", dijkstraPushed),
createButton("Clear OP", () {
clearDropDownVals();
clearInputData();
}),
createButton(graphData.getUseLengthStr(), changeLength),
createButton(graphData.getDoubleSidedStr(), changeOriented),
createButton("Save to file", fileSaver),
createButton("Load from file", fileOpener),
createButton("Help", () {
/*
String out =
" В поле \"Graph name\" можно сменить имя графу.\n";
out +=
@ -487,8 +519,8 @@ class _DrawingPageState extends State<DrawingPage> {
out +=
" Кнопки \"Save to file\" и \"Load from file\" позволяют вывести информацию в файл и загрузить информацию из файла соответственно.\n";
out +=
" Кнопка \"Help\" описывает работу с интерфейсом программы.";
showPopUp("Help:", out);
" Кнопка \"Help\" описывает работу с интерфейсом программы.";*/
showPopUp("Help:", "На переработке");
})
],
),