Open file button work
This commit is contained in:
		
							parent
							
								
									26d610b302
								
							
						
					
					
						commit
						856b11d028
					
				| @ -1,9 +1,8 @@ | |||||||
| import 'dart:io'; |  | ||||||
| 
 |  | ||||||
| import 'package:graphs/curve_painter.dart'; |  | ||||||
| import 'package:flutter/material.dart'; |  | ||||||
| import 'package:flutter/services.dart'; |  | ||||||
| import 'package:graphs/src/graph.dart'; | import 'package:graphs/src/graph.dart'; | ||||||
|  | import 'package:graphs/curve_painter.dart'; | ||||||
|  | 
 | ||||||
|  | import 'package:file_picker/file_picker.dart'; | ||||||
|  | import 'package:flutter/material.dart'; | ||||||
| 
 | 
 | ||||||
| Graphs getGraph() { | Graphs getGraph() { | ||||||
|   List<Dot> d = <Dot>[]; |   List<Dot> d = <Dot>[]; | ||||||
| @ -28,10 +27,11 @@ class _DrawingPageState extends State<DrawingPage> { | |||||||
| 
 | 
 | ||||||
|   final _textNameController = TextEditingController(); |   final _textNameController = TextEditingController(); | ||||||
|   final _textNumbController = TextEditingController(); |   final _textNumbController = TextEditingController(); | ||||||
|   final _textDistController = TextEditingController(); |   final _textDestController = TextEditingController(); | ||||||
|   final _textLnthController = TextEditingController(); |   final _textLnthController = TextEditingController(); | ||||||
|  | 
 | ||||||
|   void clearTextControllers() { |   void clearTextControllers() { | ||||||
|     _textDistController.clear(); |     _textDestController.clear(); | ||||||
|     _textNumbController.clear(); |     _textNumbController.clear(); | ||||||
|     _textLnthController.clear(); |     _textLnthController.clear(); | ||||||
|     _textNameController.clear(); |     _textNameController.clear(); | ||||||
| @ -44,7 +44,7 @@ class _DrawingPageState extends State<DrawingPage> { | |||||||
|         home: Scaffold( |         home: Scaffold( | ||||||
|       appBar: AppBar( |       appBar: AppBar( | ||||||
|           title: const Text("Graph", |           title: const Text("Graph", | ||||||
|               style: TextStyle(fontSize: 35, color: Colors.white)), |               style: TextStyle(fontSize: 30, color: Colors.white)), | ||||||
|           toolbarHeight: 110, // Set this height |           toolbarHeight: 110, // Set this height | ||||||
|           flexibleSpace: Container( |           flexibleSpace: Container( | ||||||
|             color: Colors.blue, |             color: Colors.blue, | ||||||
| @ -62,18 +62,20 @@ class _DrawingPageState extends State<DrawingPage> { | |||||||
|               ]), |               ]), | ||||||
|               addSpaceH(3), |               addSpaceH(3), | ||||||
|               Row(children: [ |               Row(children: [ | ||||||
|                 addSpaceW(screenSize / 4 - 20), |                 addSpaceW(screenSize / 8 - 4), | ||||||
|                 createInputBox("Destination number", screenSize / 4 - 5, |                 createButton("\nAdd path\n", addPathPushed), | ||||||
|                     Icons.fiber_manual_record, _textDistController), |                 createInputBox("Input length", screenSize / 4 - 25, | ||||||
|                 //addSpaceW(4), |  | ||||||
|                 createInputBox("Input length", screenSize / 4 - 5, |  | ||||||
|                     Icons.arrow_right_alt_outlined, _textLnthController), |                     Icons.arrow_right_alt_outlined, _textLnthController), | ||||||
|  |                 addSpaceW(13), | ||||||
|  |                 createButton("\nDel path\n", delPathPushed), | ||||||
|  |                 createInputBox("Destination number", screenSize / 4 - 25, | ||||||
|  |                     Icons.fiber_manual_record, _textDestController), | ||||||
|               ]), |               ]), | ||||||
|             ]), |             ]), | ||||||
|           ), |           ), | ||||||
|           actions: [ |           actions: [ | ||||||
|             IconButton( |             IconButton( | ||||||
|               onPressed: flushData, |               onPressed: clearScreen, | ||||||
|               icon: const Icon(Icons.delete_sweep), |               icon: const Icon(Icons.delete_sweep), | ||||||
|               iconSize: 60, |               iconSize: 60, | ||||||
|             ), |             ), | ||||||
| @ -85,8 +87,8 @@ class _DrawingPageState extends State<DrawingPage> { | |||||||
|           child: ButtonBar( |           child: ButtonBar( | ||||||
|             mainAxisSize: MainAxisSize.min, |             mainAxisSize: MainAxisSize.min, | ||||||
|             children: <Widget>[ |             children: <Widget>[ | ||||||
|               createButton("Hello", () {}), |               createButton("Save to file", () {}), | ||||||
|               createButton("Hi", () {}), |               createButton("Load from file", fileOpener), | ||||||
|             ], |             ], | ||||||
|           ), |           ), | ||||||
|         ), |         ), | ||||||
| @ -148,7 +150,30 @@ class _DrawingPageState extends State<DrawingPage> { | |||||||
|         showPopUp("Error", res); |         showPopUp("Error", res); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     //print(_textNameController.text); |     clearTextControllers(); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   void addPathPushed() { | ||||||
|  |     if (_textDestController.text == "") { | ||||||
|  |       showPopUp("Error", "No name in \"Dot name\" box"); | ||||||
|  |     } else { | ||||||
|  |       String? res = data.addIsolated(_textNameController.text); | ||||||
|  |       if (res != null) { | ||||||
|  |         showPopUp("Error", res); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |     clearTextControllers(); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   void delPathPushed() { | ||||||
|  |     if (_textDestController.text == "") { | ||||||
|  |       showPopUp("Error", "No name in \"Dot name\" box"); | ||||||
|  |     } else { | ||||||
|  |       String? res = data.addIsolated(_textNameController.text); | ||||||
|  |       if (res != null) { | ||||||
|  |         showPopUp("Error", res); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|     clearTextControllers(); |     clearTextControllers(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -172,7 +197,7 @@ class _DrawingPageState extends State<DrawingPage> { | |||||||
|   void addLenPushed() { |   void addLenPushed() { | ||||||
|     //data.delDot() |     //data.delDot() | ||||||
|     print( |     print( | ||||||
|         "${_textNumbController.text} -> ${_textDistController.text} = ${_textLnthController.text}"); |         "${_textNumbController.text} -> ${_textDestController.text} = ${_textLnthController.text}"); | ||||||
|     clearTextControllers(); |     clearTextControllers(); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -190,11 +215,17 @@ class _DrawingPageState extends State<DrawingPage> { | |||||||
|         ), |         ), | ||||||
|       ); |       ); | ||||||
| 
 | 
 | ||||||
|   void flushData() { |   void fileOpener() async { | ||||||
|     /*if (Platform.isWindows) { |     FilePickerResult? result = await FilePicker.platform.pickFiles(); | ||||||
|       exit(0); | 
 | ||||||
|  |     if (result != null) { | ||||||
|  |       print(result.files.single.path!); | ||||||
|  |       data.replaceDataFromFile(result.files.single.path!); | ||||||
|  |     } else { | ||||||
|  |       showPopUp("Error", "No file selected"); | ||||||
|  |       // User canceled the picker | ||||||
|     } |     } | ||||||
|     SystemChannels.platform.invokeMethod('SystemNavigator.pop');*/ |  | ||||||
|     data.flushData(); |  | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   void clearScreen() => data.flushData(); | ||||||
| } | } | ||||||
|  | |||||||
| @ -57,6 +57,20 @@ packages: | |||||||
|       url: "https://pub.dartlang.org" |       url: "https://pub.dartlang.org" | ||||||
|     source: hosted |     source: hosted | ||||||
|     version: "1.2.0" |     version: "1.2.0" | ||||||
|  |   ffi: | ||||||
|  |     dependency: transitive | ||||||
|  |     description: | ||||||
|  |       name: ffi | ||||||
|  |       url: "https://pub.dartlang.org" | ||||||
|  |     source: hosted | ||||||
|  |     version: "1.1.2" | ||||||
|  |   file_picker: | ||||||
|  |     dependency: "direct main" | ||||||
|  |     description: | ||||||
|  |       name: file_picker | ||||||
|  |       url: "https://pub.dartlang.org" | ||||||
|  |     source: hosted | ||||||
|  |     version: "4.2.0" | ||||||
|   flutter: |   flutter: | ||||||
|     dependency: "direct main" |     dependency: "direct main" | ||||||
|     description: flutter |     description: flutter | ||||||
| @ -69,11 +83,30 @@ packages: | |||||||
|       url: "https://pub.dartlang.org" |       url: "https://pub.dartlang.org" | ||||||
|     source: hosted |     source: hosted | ||||||
|     version: "1.0.4" |     version: "1.0.4" | ||||||
|  |   flutter_plugin_android_lifecycle: | ||||||
|  |     dependency: transitive | ||||||
|  |     description: | ||||||
|  |       name: flutter_plugin_android_lifecycle | ||||||
|  |       url: "https://pub.dartlang.org" | ||||||
|  |     source: hosted | ||||||
|  |     version: "2.0.4" | ||||||
|   flutter_test: |   flutter_test: | ||||||
|     dependency: "direct dev" |     dependency: "direct dev" | ||||||
|     description: flutter |     description: flutter | ||||||
|     source: sdk |     source: sdk | ||||||
|     version: "0.0.0" |     version: "0.0.0" | ||||||
|  |   flutter_web_plugins: | ||||||
|  |     dependency: transitive | ||||||
|  |     description: flutter | ||||||
|  |     source: sdk | ||||||
|  |     version: "0.0.0" | ||||||
|  |   js: | ||||||
|  |     dependency: transitive | ||||||
|  |     description: | ||||||
|  |       name: js | ||||||
|  |       url: "https://pub.dartlang.org" | ||||||
|  |     source: hosted | ||||||
|  |     version: "0.6.3" | ||||||
|   lints: |   lints: | ||||||
|     dependency: transitive |     dependency: transitive | ||||||
|     description: |     description: | ||||||
| @ -102,6 +135,13 @@ packages: | |||||||
|       url: "https://pub.dartlang.org" |       url: "https://pub.dartlang.org" | ||||||
|     source: hosted |     source: hosted | ||||||
|     version: "1.8.0" |     version: "1.8.0" | ||||||
|  |   plugin_platform_interface: | ||||||
|  |     dependency: transitive | ||||||
|  |     description: | ||||||
|  |       name: plugin_platform_interface | ||||||
|  |       url: "https://pub.dartlang.org" | ||||||
|  |     source: hosted | ||||||
|  |     version: "2.0.2" | ||||||
|   sky_engine: |   sky_engine: | ||||||
|     dependency: transitive |     dependency: transitive | ||||||
|     description: flutter |     description: flutter | ||||||
| @ -162,6 +202,7 @@ packages: | |||||||
|       name: vector_math |       name: vector_math | ||||||
|       url: "https://pub.dartlang.org" |       url: "https://pub.dartlang.org" | ||||||
|     source: hosted |     source: hosted | ||||||
|     version: "2.1.1" |     version: "2.1.0" | ||||||
| sdks: | sdks: | ||||||
|   dart: ">=2.15.0-178.1.beta <3.0.0" |   dart: ">=2.15.0-100.0.dev <3.0.0" | ||||||
|  |   flutter: ">=2.0.0" | ||||||
|  | |||||||
| @ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev | |||||||
| version: 1.0.0+1 | version: 1.0.0+1 | ||||||
| 
 | 
 | ||||||
| environment: | environment: | ||||||
|   sdk: ">=2.15.0-178.1.beta<3.0.0" |   sdk: ">=2.15.0-100.0.dev<3.0.0" | ||||||
| 
 | 
 | ||||||
| # Dependencies specify other packages that your package needs in order to work. | # Dependencies specify other packages that your package needs in order to work. | ||||||
| # To automatically upgrade your package dependencies to the latest versions | # To automatically upgrade your package dependencies to the latest versions | ||||||
| @ -29,7 +29,7 @@ environment: | |||||||
| dependencies: | dependencies: | ||||||
|   flutter: |   flutter: | ||||||
|     sdk: flutter |     sdk: flutter | ||||||
| 
 |   file_picker: ^4.2.0 | ||||||
| 
 | 
 | ||||||
|   # The following adds the Cupertino Icons font to your application. |   # The following adds the Cupertino Icons font to your application. | ||||||
|   # Use with the CupertinoIcons class for iOS style icons. |   # Use with the CupertinoIcons class for iOS style icons. | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user