Risolto un bug nella conversione, modificata la struttura della grafica di conversione e quasi terminato unità di lunghezza
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
<orderEntry type="library" name="Flutter Plugins" level="project" />
|
||||
|
||||
@@ -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<ConversionManager>{
|
||||
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: <Widget>[
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
+35
-44
@@ -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<ConversionPage>{
|
||||
|
||||
class _ConversionPage extends State<ConversionPage> {
|
||||
Node fatherNode;
|
||||
List<Node> listaNodi;
|
||||
List<TextEditingController> listaController=new List();
|
||||
List<FocusNode> listaFocus=new List();
|
||||
List<TextEditingController> listaController = new List();
|
||||
List<FocusNode> 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<ConversionPage>{
|
||||
void dispose() {
|
||||
FocusNode focus;
|
||||
TextEditingController TEC;
|
||||
for(int i=0;i<listaFocus.length;i++){
|
||||
focus=listaFocus[i];
|
||||
focus.removeListener((){});
|
||||
for (int i = 0; i < listaFocus.length; i++) {
|
||||
focus = listaFocus[i];
|
||||
focus.removeListener(() {});
|
||||
focus.dispose();
|
||||
TEC=listaController[i];
|
||||
TEC = listaController[i];
|
||||
TEC.dispose();
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
List<UnitCard> _createList(){
|
||||
List<UnitCard> listaCard=new List();
|
||||
for (int i=0; i<listaNodi.length;i++){
|
||||
Node nodo=listaNodi[i];
|
||||
List<UnitCard> _createList() {
|
||||
List<UnitCard> 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<UnitCard> listCard=_createList();
|
||||
List<UnitCard> 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);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-9
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user