Open file button work

This commit is contained in:
Морозов Андрей 2021-11-05 15:25:36 +04:00
parent 26d610b302
commit 856b11d028
3 changed files with 99 additions and 27 deletions

View File

@ -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<Dot> d = <Dot>[];
@ -28,10 +27,11 @@ class _DrawingPageState extends State<DrawingPage> {
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<DrawingPage> {
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<DrawingPage> {
]),
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<DrawingPage> {
child: ButtonBar(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
createButton("Hello", () {}),
createButton("Hi", () {}),
createButton("Save to file", () {}),
createButton("Load from file", fileOpener),
],
),
),
@ -148,7 +150,30 @@ class _DrawingPageState extends State<DrawingPage> {
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<DrawingPage> {
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<DrawingPage> {
),
);
void flushData() {
/*if (Platform.isWindows) {
exit(0);
}
SystemChannels.platform.invokeMethod('SystemNavigator.pop');*/
data.flushData();
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
}
}
void clearScreen() => data.flushData();
}

View File

@ -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"

View File

@ -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.