I need your help please,
I want to multiply the values from different text fields. I am facing the problem that * cant be used with TexteditingController() in:
void _calculation() {
_volume = lenCon * widCon * higCon;
print(_volume);
}
Do I need to transfrom my Variables like lenCon to double before? How can I do that? var lenConInt = double.parse(lenCon); doesnt work.
The RaisedButton must execute _calculation and change the Text with the proper Value. Do I need a StatlessWidget for that or SetState?
Thanks in Advance!
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var _volume = 0;
// var _lenght;
// var _width;
// var _hight;
void _calculation() {
_volume = lenCon * widCon * higCon;
print(_volume);
}
final lenCon = new TextEditingController();
final widCon = new TextEditingController();
final higCon = new TextEditingController();
// var lenConInt = double.parse(lenCon);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
controller: lenCon,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Länge',
),
),
TextField(
controller: widCon,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Breite',
),
),
TextField(
controller: higCon,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Höhe',
),
),
RaisedButton(
onPressed: (_calculation),
child: Text('Berechnen'),
),
Text('Your Volume is: $_volume'),
],
),
),
),
);
}
}
var lenConDouble = double.parse(lenCon.text);.textretreives the entered value from the TextEditingController flutter.dev/docs/cookbook/forms/retrieve-input