From 856b11d028e4e6aa14616c55dac4bdd9c61a8d53 Mon Sep 17 00:00:00 2001 From: lnd212 Date: Fri, 5 Nov 2021 15:25:36 +0400 Subject: [PATCH] Open file button work --- flutter/lib/pages/drawing_page.dart | 77 ++++++++++++++++++++--------- flutter/pubspec.lock | 45 ++++++++++++++++- flutter/pubspec.yaml | 4 +- 3 files changed, 99 insertions(+), 27 deletions(-) diff --git a/flutter/lib/pages/drawing_page.dart b/flutter/lib/pages/drawing_page.dart index 35f31df..8b3bef5 100644 --- a/flutter/lib/pages/drawing_page.dart +++ b/flutter/lib/pages/drawing_page.dart @@ -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/curve_painter.dart'; + +import 'package:file_picker/file_picker.dart'; +import 'package:flutter/material.dart'; Graphs getGraph() { List d = []; @@ -28,10 +27,11 @@ class _DrawingPageState extends State { final _textNameController = TextEditingController(); final _textNumbController = TextEditingController(); - final _textDistController = TextEditingController(); + final _textDestController = TextEditingController(); final _textLnthController = TextEditingController(); + void clearTextControllers() { - _textDistController.clear(); + _textDestController.clear(); _textNumbController.clear(); _textLnthController.clear(); _textNameController.clear(); @@ -44,7 +44,7 @@ class _DrawingPageState extends State { home: Scaffold( appBar: AppBar( title: const Text("Graph", - style: TextStyle(fontSize: 35, color: Colors.white)), + style: TextStyle(fontSize: 30, color: Colors.white)), toolbarHeight: 110, // Set this height flexibleSpace: Container( color: Colors.blue, @@ -62,18 +62,20 @@ class _DrawingPageState extends State { ]), addSpaceH(3), Row(children: [ - addSpaceW(screenSize / 4 - 20), - createInputBox("Destination number", screenSize / 4 - 5, - Icons.fiber_manual_record, _textDistController), - //addSpaceW(4), - createInputBox("Input length", screenSize / 4 - 5, + addSpaceW(screenSize / 8 - 4), + createButton("\nAdd path\n", addPathPushed), + createInputBox("Input length", screenSize / 4 - 25, 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: [ IconButton( - onPressed: flushData, + onPressed: clearScreen, icon: const Icon(Icons.delete_sweep), iconSize: 60, ), @@ -85,8 +87,8 @@ class _DrawingPageState extends State { child: ButtonBar( mainAxisSize: MainAxisSize.min, children: [ - createButton("Hello", () {}), - createButton("Hi", () {}), + createButton("Save to file", () {}), + createButton("Load from file", fileOpener), ], ), ), @@ -148,7 +150,30 @@ class _DrawingPageState extends State { 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(); } @@ -172,7 +197,7 @@ class _DrawingPageState extends State { void addLenPushed() { //data.delDot() print( - "${_textNumbController.text} -> ${_textDistController.text} = ${_textLnthController.text}"); + "${_textNumbController.text} -> ${_textDestController.text} = ${_textLnthController.text}"); clearTextControllers(); } @@ -190,11 +215,17 @@ class _DrawingPageState extends State { ), ); - void flushData() { - /*if (Platform.isWindows) { - exit(0); + void fileOpener() async { + FilePickerResult? result = await FilePicker.platform.pickFiles(); + + 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(); } diff --git a/flutter/pubspec.lock b/flutter/pubspec.lock index 98a9221..2694ab6 100644 --- a/flutter/pubspec.lock +++ b/flutter/pubspec.lock @@ -57,6 +57,20 @@ packages: url: "https://pub.dartlang.org" source: hosted 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: dependency: "direct main" description: flutter @@ -69,11 +83,30 @@ packages: url: "https://pub.dartlang.org" source: hosted 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: dependency: "direct dev" description: flutter source: sdk 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: dependency: transitive description: @@ -102,6 +135,13 @@ packages: url: "https://pub.dartlang.org" source: hosted 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: dependency: transitive description: flutter @@ -162,6 +202,7 @@ packages: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" + version: "2.1.0" 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" diff --git a/flutter/pubspec.yaml b/flutter/pubspec.yaml index 2ed0e18..3c41b83 100644 --- a/flutter/pubspec.yaml +++ b/flutter/pubspec.yaml @@ -18,7 +18,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 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. # To automatically upgrade your package dependencies to the latest versions @@ -29,7 +29,7 @@ environment: dependencies: flutter: sdk: flutter - + file_picker: ^4.2.0 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.