import 'package:flutter/material.dart';
void main() => runApp(new CalculatorApp());
class CalculatorApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(title:'Bending Calculator',
home: Calculator()
);
}
}
class Calculator extends StatefulWidget {
@override
State<StatefulWidget> createState() => Calculatore();
}
class Calculatore extends State<Calculator> {
final a = TextEditingController();
final b = TextEditingController();
final c = TextEditingController();
// controller mentioned
String total= "";
void calculate() {
int numberA = int.parse(a.text);
int numberB = int.parse(b.text);
int numberC = int.parse(c.text);
int result;
// if numberA have value then answer will be a+c
if(
// what condition to do here for between choosing between textfields a or b.
// i tried numberB ==null that does not work
// very much confused, no idea what to do please help
){
result = numberA + numberC
} else{ result = numberB + numberC
}
setState(() {
total = "$result";
});
}
@override
Widget build(BuildContext context) {
return Scaffold(appBar: AppBar(title:Text("Calculator")),
body: SafeArea(
child: ListView(
children: <Widget>[
Row( mainAxisAlignment: MainAxisAlignment.center ,
children: <Widget>[
// первое текстовое поле
Container(width: MediaQuery.of(context).size.width *0.45 ,height: 50,
child: TextField(
controller: a,
decoration: InputDecoration(hintText: " Enter a value"),
keyboardType: TextInputType.number),
),
Container(width: MediaQuery.of(context).size.width * 0.04,height: 50,),
// second textfield
Container(width: MediaQuery.of(context).size.width* 0.45,height: 50,
child: TextField(
controller: b,
decoration: InputDecoration(hintText: " Enter b value"),
keyboardType: TextInputType.number),), ],
),
Row(mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// третье текстовое поле
Контейнер (ширина: MediaQuery.of (context) .size.width * 0.9, высота: 50, child: TextField (контроллер: c, украшение: InputDecoration (hintText: «Enter c value»), keyboardType: TextInputType.number),),],), Row (mainAxisAlignment: MainAxisAlignment.center, потомки: [
// кнопка
RaisedButton(
onPressed: calculate,
child: Text('Calculate'),),
],
),
Text(" Total : $total", style: TextStyle(fontSize: 20.0),),
],
))
);
}
}