diff --git a/converter_pro.iml b/converter_pro.iml
index e5c8371..0dd01cf 100644
--- a/converter_pro.iml
+++ b/converter_pro.iml
@@ -10,6 +10,7 @@
+
diff --git a/lib/ConversionManager.dart b/lib/ConversionManager.dart
new file mode 100644
index 0000000..17bb44f
--- /dev/null
+++ b/lib/ConversionManager.dart
@@ -0,0 +1,93 @@
+import 'package:converter_pro/ConversionPage.dart';
+import 'package:converter_pro/Utils.dart';
+import 'package:flutter/material.dart';
+
+class ConversionManager extends StatefulWidget{
+ @override
+ _ConversionManager createState() => new _ConversionManager();
+
+}
+
+class _ConversionManager extends State{
+ static Node metro=Node(name: "Metro",
+ leafNodes: [
+ Node(isMultiplication: false, coefficient: 1000.0, name: "Millimetro",),
+ Node(isMultiplication: false, coefficient: 1000000.0, name: "Micrometro", ),
+ Node(isMultiplication: false, coefficient: 1000000000.0, name: "Nanometro",),
+ Node(isMultiplication: true, coefficient: 1000.0, name: "Chilometro",leafNodes: [
+ Node(isMultiplication: true, coefficient: 149597870.7, name: "Unità Astronomica",leafNodes: [
+ Node(isMultiplication: true, coefficient: 63241.1, name: "Anno Luce",),
+ ]),
+ ]),
+ Node(isMultiplication: false, coefficient: 100.0, name: "Centimetro", leafNodes: [
+ Node(isMultiplication: true, coefficient: 2.54, name: "Pollice", leafNodes: [
+ Node(isMultiplication: true, coefficient: 12.0, name: "Piede"),
+ ]),
+ ]),
+
+ ]
+ );
+
+
+ int currentPage=0;
+
+ @override
+ Widget build(BuildContext context) {
+
+ return Scaffold(
+ appBar: AppBar(title: new Text("Lunghezza"),),
+ drawer: new Drawer(child: ListView(
+ // Important: Remove any padding from the ListView.
+ padding: EdgeInsets.zero,
+ children: [
+ DrawerHeader(
+ child: Text('Converter PRO'),
+ decoration: BoxDecoration(
+ color: Colors.red,
+ ),
+ ),
+ ListTile(
+ title: Text("Lunghezza"),
+ selected: true,
+ onTap: () {
+ if(currentPage!=0) {
+ setState((){
+ currentPage=0;
+ });
+ }
+ },
+ ),
+ ListTile(
+ title: Text("Superficie"),
+ onTap: () {
+ // Update the state of the app
+ // ...
+ },
+ ),
+ ListTile(
+ title: Text("Volume"),
+ onTap: () {
+ // Update the state of the app
+ // ...
+ },
+ ),
+ ListTile(
+ title: Text("Tempo"),
+ onTap: () {
+ // Update the state of the app
+ // ...
+ },
+ ),
+ ListTile(
+ title: Text("Temperatura"),
+ onTap: () {
+ // Update the state of the app
+ // ...
+ },
+ ),
+ ],
+ ),),
+ body: currentPage==0 ? ConversionPage(metro) : ConversionPage(metro)
+ );
+ }
+}
diff --git a/lib/ConversionPage.dart b/lib/ConversionPage.dart
index 8004286..4c14884 100644
--- a/lib/ConversionPage.dart
+++ b/lib/ConversionPage.dart
@@ -2,8 +2,7 @@ import 'package:converter_pro/Utils.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
-class ConversionPage extends StatefulWidget{
-
+class ConversionPage extends StatefulWidget {
ConversionPage(this.fatherNode);
Node fatherNode;
@@ -12,34 +11,32 @@ class ConversionPage extends StatefulWidget{
_ConversionPage createState() => new _ConversionPage(fatherNode);
}
-class _ConversionPage extends State{
-
+class _ConversionPage extends State {
Node fatherNode;
List listaNodi;
- List listaController=new List();
- List listaFocus=new List();
+ List listaController = new List();
+ List listaFocus = new List();
Node selectedNode;
- _ConversionPage(Node fatherNode){
- this.fatherNode=fatherNode;
- listaNodi=fatherNode.getNodiFiglio();
-
+ _ConversionPage(Node fatherNode) {
+ this.fatherNode = fatherNode;
+ listaNodi = fatherNode.getNodiFiglio();
}
@override
void initState() {
super.initState();
- for(Node node in listaNodi){
+ for (Node node in listaNodi) {
listaController.add(new TextEditingController());
- FocusNode focus=new FocusNode();
- focus.addListener((){
+ FocusNode focus = new FocusNode();
+ focus.addListener(() {
if (focus.hasFocus) {
- if(selectedNode!=null) {
+ if (selectedNode != null) {
selectedNode.selectedNode = false;
}
- node.selectedNode=true;
- node.convertedNode=true;
- selectedNode=node;
+ node.selectedNode = true;
+ node.convertedNode = true;
+ selectedNode = node;
}
});
listaFocus.add(focus);
@@ -50,60 +47,54 @@ class _ConversionPage extends State{
void dispose() {
FocusNode focus;
TextEditingController TEC;
- for(int i=0;i _createList(){
- List listaCard=new List();
- for (int i=0; i _createList() {
+ List listaCard = new List();
+ for (int i = 0; i < listaNodi.length; i++) {
+ Node nodo = listaNodi[i];
TextEditingController controller;
- controller=listaController[i];
+ controller = listaController[i];
- if(nodo.value!=null && !nodo.selectedNode)
+ if (nodo.value != null && !nodo.selectedNode)
controller.text = nodo.value.toString();
- else if(nodo.value==null && !nodo.selectedNode)
- controller.text = "";
+ else if (nodo.value == null && !nodo.selectedNode) controller.text = "";
listaCard.add(new UnitCard(
node: nodo,
textField: TextField(
- style: TextStyle(fontSize: 16.0,color: Colors.black,),
- keyboardType: TextInputType.numberWithOptions(decimal: true,signed: false),
+ style: TextStyle(
+ fontSize: 16.0,
+ color: Colors.black,
+ ),
+ keyboardType:
+ TextInputType.numberWithOptions(decimal: true, signed: false),
controller: controller,
focusNode: listaFocus[i],
- onChanged: (String txt){
+ onChanged: (String txt) {
nodo.value = txt == "" ? null : double.parse(txt);
setState(() {
fatherNode.ResetConvertedNode();
fatherNode.Convert();
});
},
- )
- ));
-
+ )));
}
return listaCard;
}
-
@override
Widget build(BuildContext context) {
- List listCard=_createList();
+ List listCard = _createList();
- return Scaffold(
- appBar: AppBar(title: new Text("Lunghezza"),),
- body: ListView(
- padding: new EdgeInsets.all(10.0),
- children: listCard
- ),
- );
+ return ListView(padding: new EdgeInsets.all(10.0), children: listCard);
}
}
diff --git a/lib/Utils.dart b/lib/Utils.dart
index f898bfe..7dd0adf 100644
--- a/lib/Utils.dart
+++ b/lib/Utils.dart
@@ -63,11 +63,11 @@ class Node {
: (node.isMultiplication ? node.value * node.coefficient : node.value / node.coefficient); //metto in questo nodo il valore convertito
convertedNode = true;
_ApplyDown(); //converto i nodi sottostanti
- } else { //se non c'è valore
- if (node.leafNodes != null) { //Però ha almeno un nodo foglia
+ }
+ else if (node.leafNodes != null) { //Però ha almeno un nodo foglia
node.Convert(); //ripeti la procedura
- Convert();
- }
+ if(node.convertedNode)
+ Convert();
}
}
}
diff --git a/lib/main.dart b/lib/main.dart
index f0e64e7..428fab8 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -1,22 +1,15 @@
-import 'package:converter_pro/ConversionPage.dart';
-import 'package:converter_pro/Utils.dart';
+import 'package:converter_pro/ConversionManager.dart';
import 'package:flutter/material.dart';
void main() => runApp(new App());
class App extends StatelessWidget {
- static Node foot=Node(isMultiplication: true, coefficient: 12.0, name: "foot", selectedNode: false, convertedNode: false);
- static Node inch=Node(isMultiplication: true, coefficient: 2.54, name: "inch", leafNodes: [foot], selectedNode: false, convertedNode: false);
- static Node millimetro=Node(isMultiplication: false, coefficient: 10.0, name: "millimetro", selectedNode: false, convertedNode: false);
- static Node centimetro=Node(isMultiplication: false, coefficient: 100.0, name: "centimetro", leafNodes: [millimetro,inch], selectedNode: false, convertedNode: false);
- static Node metro=Node(name: "metro", leafNodes: [centimetro], selectedNode: false, convertedNode: false);
-
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'FCM - Calculator',
- home: ConversionPage(metro),
+ home: ConversionManager(),
theme: ThemeData(
primaryColor: Colors.red,
accentColor: Colors.indigo,