diff --git a/flutter/lib/pages/drawing_page.dart b/flutter/lib/pages/drawing_page.dart index c98e583..426256d 100644 --- a/flutter/lib/pages/drawing_page.dart +++ b/flutter/lib/pages/drawing_page.dart @@ -26,7 +26,10 @@ class _DrawingPageState extends State { Graphs graphData = getGraph(); List? bfsPath; List? dfsAccessTable; - int? dfsStartDot; + int? startDot; + int? endDot; + String? dropdownValue1; + String? dropdownValue2; final _textNameController = TextEditingController(); final _textNumbController = TextEditingController(); @@ -34,11 +37,19 @@ class _DrawingPageState extends State { final _textLnthController = TextEditingController(); final _textGrNmController = TextEditingController(); - void clearTextControllers() { - _textDestController.clear(); - _textNumbController.clear(); - _textLnthController.clear(); - _textNameController.clear(); + void clearInputData() { + setState(() { + _textDestController.clear(); + _textNumbController.clear(); + _textLnthController.clear(); + _textNameController.clear(); + dropdownValue1 = null; + dropdownValue2 = null; + /*startDot = null; + bfsPath = null; + dfsAccessTable = null; + endDot = null;*/ + }); } @override @@ -72,17 +83,19 @@ class _DrawingPageState extends State { ]), addSpaceH(3), Row(children: [ - addSpaceW(5), + addSpaceW(6), createInputBox( "Name", screenSize / 8 - 25, null, _textGrNmController), //addSpaceW(screenSize / 8 - 4), createButton("\nDel dot \n", delDotPushed), - createInputBox("Dot number", screenSize / 4 - 25, - Icons.fiber_manual_record, _textNumbController), - addSpaceW(13), + //createInputBox("Dot number", screenSize / 4 - 25, Icons.fiber_manual_record, _textNumbController), + addSpaceW(54), + dropList1(screenSize / 4 - 80), + addSpaceW(54), createButton("\nDel path\n", delPathPushed), - createInputBox("Destination number", screenSize / 4 - 25, - Icons.fiber_manual_record, _textDestController), + addSpaceW(54), + dropList2(screenSize / 4 - 80), + //createInputBox("Destination number", screenSize / 4 - 25, Icons.fiber_manual_record, _textDestController), ]), ]), ), @@ -97,8 +110,9 @@ class _DrawingPageState extends State { painter: CurvePainter( graphData: graphData, bfsPath: bfsPath, - dfsStart: dfsStartDot, - dfsAccessTable: dfsAccessTable), + dfsAccessTable: dfsAccessTable, + start: startDot, + end: endDot), child: Align( alignment: Alignment.topRight, child: ButtonBar( @@ -106,7 +120,14 @@ class _DrawingPageState extends State { children: [ createButton("Bfs", bfsPushed), 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.getDoubleSidedStr(), changeOriented), /*Text(_textGrNmController.text, @@ -238,26 +259,24 @@ class _DrawingPageState extends State { showPopUp("Error", res); } } - clearTextControllers(); + clearInputData(); }); } void addPathPushed() { setState(() { - if (_textNumbController.text == "") { - showPopUp("Error", "No number in \"Dot number\" box"); - } else if (_textDestController.text == "") { - showPopUp("Error", "No number in \"Destination number\" box"); + 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.tryParse(_textNumbController.text); - int? to = int.tryParse(_textDestController.text); + int? from = int.parse(dropdownValue1!); + int? to = int.parse(dropdownValue2!); int? len = int.tryParse(_textLnthController.text); - if (from == null || - to == null || - (len == null && graphData.getUseLengthBool())) { + if (len == null && graphData.getUseLengthBool()) { showPopUp("Error", "Can't parse input.\nInts only allowed in \"Dot number\", \"Destination number\" and \"Input length\""); } else { @@ -268,7 +287,7 @@ class _DrawingPageState extends State { } } } - clearTextControllers(); + clearInputData(); }); } @@ -305,13 +324,13 @@ class _DrawingPageState extends State { } } } - clearTextControllers(); + clearInputData(); }); } void delDotPushed() { setState(() { - if (_textNumbController.text == "") { + /*if (_textNumbController.text == "") { showPopUp("Error", "No number in \"Dot number\" box"); } else { int? dot = int.tryParse(_textNumbController.text); @@ -323,8 +342,13 @@ class _DrawingPageState extends State { 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 { void bfsPushed() { setState(() { - dfsAccessTable = null; bfsPath = null; - if (_textNumbController.text == "") { + dfsAccessTable = null; + startDot = null; + endDot = null; + if (dropdownValue1 == null) { showPopUp("Error", "No number in \"Dot number\" box"); - } else if (_textDestController.text == "") { + } else if (dropdownValue2 == null) { showPopUp("Error", "No number in \"Destination number\" box"); } 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 { - bfsPath = graphData.bfsPath(from, to); - if (bfsPath == null) { - showPopUp("Info", "There is no path"); - } - print(bfsPath); + startDot = int.parse(dropdownValue1!); + endDot = int.parse(dropdownValue2!); + + bfsPath = graphData.bfsPath(startDot!, endDot!); + if (bfsPath == null) { + showPopUp("Info", "There is no path"); } + print(bfsPath); } - clearTextControllers(); }); + clearInputData(); } void dfsPushed() { setState(() { bfsPath = null; - bfsPath = null; - if (_textNumbController.text == "") { + dfsAccessTable = null; + startDot = null; + endDot = null; + if (dropdownValue1 == null) { showPopUp("Error", "No number in \"Dot number\" box"); } else { - int? from = int.tryParse(_textNumbController.text); - if (from == null) { - showPopUp("Error", - "Can't parse input.\nInts only allowed in \"Dot number\"."); - } else { - dfsAccessTable = graphData.dfsIterative(from); - if (dfsAccessTable == null) { - showPopUp("Err", "report this error."); - } - print(dfsAccessTable); + startDot = int.parse(dropdownValue1!); + dfsAccessTable = graphData.dfsIterative(startDot!); + if (dfsAccessTable == null) { + showPopUp("Err", "report this error."); } + print(dfsAccessTable); } - clearTextControllers(); + clearInputData(); }); } //*********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, + ); + } }