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

This commit is contained in:
Морозов Андрей 2021-11-10 11:26:25 +00:00
parent 3950fabb86
commit 276e7d36ed
1 changed files with 148 additions and 57 deletions

View File

@ -26,7 +26,10 @@ class _DrawingPageState extends State<DrawingPage> {
Graphs graphData = getGraph(); Graphs graphData = getGraph();
List<int>? bfsPath; List<int>? bfsPath;
List<bool>? dfsAccessTable; List<bool>? dfsAccessTable;
int? dfsStartDot; int? startDot;
int? endDot;
String? dropdownValue1;
String? dropdownValue2;
final _textNameController = TextEditingController(); final _textNameController = TextEditingController();
final _textNumbController = TextEditingController(); final _textNumbController = TextEditingController();
@ -34,11 +37,19 @@ class _DrawingPageState extends State<DrawingPage> {
final _textLnthController = TextEditingController(); final _textLnthController = TextEditingController();
final _textGrNmController = TextEditingController(); final _textGrNmController = TextEditingController();
void clearTextControllers() { void clearInputData() {
setState(() {
_textDestController.clear(); _textDestController.clear();
_textNumbController.clear(); _textNumbController.clear();
_textLnthController.clear(); _textLnthController.clear();
_textNameController.clear(); _textNameController.clear();
dropdownValue1 = null;
dropdownValue2 = null;
/*startDot = null;
bfsPath = null;
dfsAccessTable = null;
endDot = null;*/
});
} }
@override @override
@ -72,17 +83,19 @@ class _DrawingPageState extends State<DrawingPage> {
]), ]),
addSpaceH(3), addSpaceH(3),
Row(children: [ Row(children: [
addSpaceW(5), addSpaceW(6),
createInputBox( createInputBox(
"Name", screenSize / 8 - 25, null, _textGrNmController), "Name", screenSize / 8 - 25, null, _textGrNmController),
//addSpaceW(screenSize / 8 - 4), //addSpaceW(screenSize / 8 - 4),
createButton("\nDel dot \n", delDotPushed), createButton("\nDel dot \n", delDotPushed),
createInputBox("Dot number", screenSize / 4 - 25, //createInputBox("Dot number", screenSize / 4 - 25, Icons.fiber_manual_record, _textNumbController),
Icons.fiber_manual_record, _textNumbController), addSpaceW(54),
addSpaceW(13), dropList1(screenSize / 4 - 80),
addSpaceW(54),
createButton("\nDel path\n", delPathPushed), createButton("\nDel path\n", delPathPushed),
createInputBox("Destination number", screenSize / 4 - 25, addSpaceW(54),
Icons.fiber_manual_record, _textDestController), dropList2(screenSize / 4 - 80),
//createInputBox("Destination number", screenSize / 4 - 25, Icons.fiber_manual_record, _textDestController),
]), ]),
]), ]),
), ),
@ -97,8 +110,9 @@ class _DrawingPageState extends State<DrawingPage> {
painter: CurvePainter( painter: CurvePainter(
graphData: graphData, graphData: graphData,
bfsPath: bfsPath, bfsPath: bfsPath,
dfsStart: dfsStartDot, dfsAccessTable: dfsAccessTable,
dfsAccessTable: dfsAccessTable), start: startDot,
end: endDot),
child: Align( child: Align(
alignment: Alignment.topRight, alignment: Alignment.topRight,
child: ButtonBar( child: ButtonBar(
@ -106,7 +120,14 @@ class _DrawingPageState extends State<DrawingPage> {
children: <Widget>[ children: <Widget>[
createButton("Bfs", bfsPushed), createButton("Bfs", bfsPushed),
createButton("Dfs", dfsPushed), createButton("Dfs", dfsPushed),
createButton("Clear dfs or bfs", () => bfsPath = null), createButton("Clear dfs or bfs", () {
setState(() {
bfsPath = null;
dfsAccessTable = null;
startDot = null;
endDot = null;
});
}),
createButton(graphData.getUseLengthStr(), changeLength), createButton(graphData.getUseLengthStr(), changeLength),
createButton(graphData.getDoubleSidedStr(), changeOriented), createButton(graphData.getDoubleSidedStr(), changeOriented),
/*Text(_textGrNmController.text, /*Text(_textGrNmController.text,
@ -238,26 +259,24 @@ class _DrawingPageState extends State<DrawingPage> {
showPopUp("Error", res); showPopUp("Error", res);
} }
} }
clearTextControllers(); clearInputData();
}); });
} }
void addPathPushed() { void addPathPushed() {
setState(() { setState(() {
if (_textNumbController.text == "") { if (dropdownValue1 == null) {
showPopUp("Error", "No number in \"Dot number\" box"); showPopUp("Error", "Select output dot");
} else if (_textDestController.text == "") { } else if (dropdownValue2 == null) {
showPopUp("Error", "No number in \"Destination number\" box"); showPopUp("Error", "select input dot");
} else if (_textLnthController.text == "" && } else if (_textLnthController.text == "" &&
graphData.getUseLengthBool()) { graphData.getUseLengthBool()) {
showPopUp("Error", "No length in \"Input length\" box"); showPopUp("Error", "No length in \"Input length\" box");
} else { } else {
int? from = int.tryParse(_textNumbController.text); int? from = int.parse(dropdownValue1!);
int? to = int.tryParse(_textDestController.text); int? to = int.parse(dropdownValue2!);
int? len = int.tryParse(_textLnthController.text); int? len = int.tryParse(_textLnthController.text);
if (from == null || if (len == null && graphData.getUseLengthBool()) {
to == null ||
(len == null && graphData.getUseLengthBool())) {
showPopUp("Error", showPopUp("Error",
"Can't parse input.\nInts only allowed in \"Dot number\", \"Destination number\" and \"Input length\""); "Can't parse input.\nInts only allowed in \"Dot number\", \"Destination number\" and \"Input length\"");
} else { } else {
@ -268,7 +287,7 @@ class _DrawingPageState extends State<DrawingPage> {
} }
} }
} }
clearTextControllers(); clearInputData();
}); });
} }
@ -305,13 +324,13 @@ class _DrawingPageState extends State<DrawingPage> {
} }
} }
} }
clearTextControllers(); clearInputData();
}); });
} }
void delDotPushed() { void delDotPushed() {
setState(() { setState(() {
if (_textNumbController.text == "") { /*if (_textNumbController.text == "") {
showPopUp("Error", "No number in \"Dot number\" box"); showPopUp("Error", "No number in \"Dot number\" box");
} else { } else {
int? dot = int.tryParse(_textNumbController.text); int? dot = int.tryParse(_textNumbController.text);
@ -323,8 +342,13 @@ class _DrawingPageState extends State<DrawingPage> {
showPopUp("Error", res); showPopUp("Error", res);
} }
} }
}*/
if (dropdownValue1 != null) {
graphData.delDot(int.parse(dropdownValue1!));
} else {
showPopUp("Error", "Nothing in input");
} }
clearTextControllers(); clearInputData();
}); });
} }
@ -366,51 +390,118 @@ class _DrawingPageState extends State<DrawingPage> {
void bfsPushed() { void bfsPushed() {
setState(() { setState(() {
dfsAccessTable = null;
bfsPath = null; bfsPath = null;
if (_textNumbController.text == "") { dfsAccessTable = null;
startDot = null;
endDot = null;
if (dropdownValue1 == null) {
showPopUp("Error", "No number in \"Dot number\" box"); showPopUp("Error", "No number in \"Dot number\" box");
} else if (_textDestController.text == "") { } else if (dropdownValue2 == null) {
showPopUp("Error", "No number in \"Destination number\" box"); showPopUp("Error", "No number in \"Destination number\" box");
} else { } else {
int? from = int.tryParse(_textNumbController.text); startDot = int.parse(dropdownValue1!);
int? to = int.tryParse(_textDestController.text); endDot = int.parse(dropdownValue2!);
if (from == null || to == null) {
showPopUp("Error", bfsPath = graphData.bfsPath(startDot!, endDot!);
"Can't parse input.\nInts only allowed in \"Dot number\" and \"Destination number\"");
} else {
bfsPath = graphData.bfsPath(from, to);
if (bfsPath == null) { if (bfsPath == null) {
showPopUp("Info", "There is no path"); showPopUp("Info", "There is no path");
} }
print(bfsPath); print(bfsPath);
} }
}
clearTextControllers();
}); });
clearInputData();
} }
void dfsPushed() { void dfsPushed() {
setState(() { setState(() {
bfsPath = null; bfsPath = null;
bfsPath = null; dfsAccessTable = null;
if (_textNumbController.text == "") { startDot = null;
endDot = null;
if (dropdownValue1 == null) {
showPopUp("Error", "No number in \"Dot number\" box"); showPopUp("Error", "No number in \"Dot number\" box");
} else { } else {
int? from = int.tryParse(_textNumbController.text); startDot = int.parse(dropdownValue1!);
if (from == null) { dfsAccessTable = graphData.dfsIterative(startDot!);
showPopUp("Error",
"Can't parse input.\nInts only allowed in \"Dot number\".");
} else {
dfsAccessTable = graphData.dfsIterative(from);
if (dfsAccessTable == null) { if (dfsAccessTable == null) {
showPopUp("Err", "report this error."); showPopUp("Err", "report this error.");
} }
print(dfsAccessTable); print(dfsAccessTable);
} }
} clearInputData();
clearTextControllers();
}); });
} }
//*********ButtonsFunctions********* //*********ButtonsFunctions*********
SizedBox dropList1(double width) {
var button = DropdownButton(
hint: const Text(
'Select Dot',
style: TextStyle(color: Colors.white, fontSize: 13),
), // Not necessary for Option 1
alignment: AlignmentDirectional.centerEnd,
value: dropdownValue1,
isDense: true,
borderRadius: const BorderRadius.all(Radius.circular(20)),
dropdownColor: Colors.green.shade800,
style: const TextStyle(
//background: Paint()..color = Colors.white,
color: Colors.white,
fontSize: 18,
),
onChanged: (String? newValue) {
setState(() {
dropdownValue1 = newValue;
});
},
items: graphData.getDots().map((location) {
return DropdownMenuItem(
child: Text(location.getName()),
value: location.num.toString(),
);
}).toList(),
);
return SizedBox(
child: button,
width: width,
);
}
SizedBox dropList2(double width) {
var button = DropdownButton(
hint: const Text(
'Select Dot',
style: TextStyle(color: Colors.white, fontSize: 13),
), // Not necessary for Option 1
alignment: AlignmentDirectional.centerEnd,
value: dropdownValue2,
isDense: true,
borderRadius: const BorderRadius.all(Radius.circular(20)),
dropdownColor: Colors.green.shade800,
style: const TextStyle(
//background: Paint()..color = Colors.white,
color: Colors.white,
fontSize: 18,
),
onChanged: (String? newValue) {
setState(() {
dropdownValue2 = newValue;
});
},
items: graphData.getDots().map((location) {
return DropdownMenuItem(
child: Text(location.getName()),
value: location.num.toString(),
);
}).toList(),
);
return SizedBox(
child: button,
width: width,
);
}
} }