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