Aktualisierung Textfeld im flattern auf den button klicken
Bin ich, eine app zu entwickeln, die auf flattern, die auf dem Hauptbildschirm habe ich eine Taste, es öffnet sich ein weiterer Bildschirm, die innerhalb einer Methode. auf diesem Bildschirm will ich so machen manche Berechnung wie unter Benutzer-Eingabe und Aktualisierung von text-Feld, Klick auf den button die Methode calculateAmount genannt, welche updates variable insgesamt die spiegelt zu text-Feld text-Feld wird nicht aktualisiert, es werden nur updates auf drücken fertig auf der Tastatur... wie kann man um diese Aufgabe.
hier ist mein code:
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,
home: new homePage()
));
}
class homePage extends StatefulWidget {
@override
homePageState createState() => new homePageState();
}
class homePageState extends State<homePage> {
double metal = 0.0;
double total = 0.0;
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("APP-Title",), backgroundColor: Colors.orange),
body: new Container(
child: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Expanded(child: new RaisedButton.icon(
color: Colors.orange,
icon: const Icon(
Icons.info, size: 25.0, color: Colors.white,),
label: new Text('Calculate', style: new TextStyle(
color: Colors.white
)),
onPressed: () {
calculateWindow();
),),
],
)
],
)
),
),
);
}
void calculateWindow(){
Navigator.of(context).push(
new MaterialPageRoute(
builder: (context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Calculator'),
backgroundColor: Colors.orange,
),
body: new ListView(
children: <Widget>[
new Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Container(
height: 50.0,
width: 360.0,
decoration: new BoxDecoration(
color: Colors.orange,
shape: BoxShape.rectangle,
),
child: new Center(
child: new Row(
children: <Widget>[
new Expanded(
child: new Container(
child: new Text("Gold & Silver in Sold & Ornaments",
style: textStyle,
textAlign: textAlign
),
),
),
new Container(
height: 40.0,
width: 80.0,
decoration: new BoxDecoration(
color: Colors.white),
child: new TextField(
keyboardType: TextInputType.number,
onSubmitted : (String value) {
try {
metal = double.parse(value.toString());
print(total);
} catch (exception) {
metal = 0.0;
}
}
),
),
],
),
),
),
],
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Expanded(
child: new Container(
width: 50.0,
child: new RaisedButton.icon(
color: Colors.grey,
icon: const Icon(
Icons.check, size: 25.0, color: Colors.white,),
label: new Text('Calculate', style: new TextStyle(
color: Colors.white,
)),
onPressed: calculateAmount,
),
),
),
],
),
new Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Container(
height: 50.0,
width: 350.0,
decoration: new BoxDecoration(
color: Colors.blueGrey,
shape: BoxShape.rectangle,
),
child: new Center(
child: new Row(
children: <Widget>[
new Expanded(
child: new Container(
child: new Text("Total Amount:",
style: new TextStyle(
color: Colors.white,),
textAlign: TextAlign.left,),
),
),
new Container(
child: new Text(
'$total',
textAlign: TextAlign.left,
overflow: TextOverflow.ellipsis,
style: textStyle,
textDirection: TextDirection.ltr,
)
),
],
),
),
),
],
),
],
),
);
},
),
);
}
void calculateAmount(){
setState((){
total = metal + 0.025;
});
}
}
- Wo Sie erstellen Ihre Gesamt - & Metall-variable? Es ist nicht in den code.
- Sorry dhuma ich vergaß hinzuzufügen, wie Sie es in der Klasse homepage.
- Bitte aktualisieren Sie den richtigen code, damit ich Ihnen helfen kann
- seine jetzt aktualisiert...
- Der code sollte nur enthalten, was erforderlich ist, um sich zu reproduzieren. Ich kann nicht imaging Polsterung oder ähnliches in irgendeiner Weise in Beziehung zu dem problem.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ich nicht wirklich verstehen, was ist die gewünschte Leistung, die Sie wollen, aber in diesem Beispiel kann hilfreich sein, um Ihnen zu zeigen, wo die Dinge schief gelaufen in Ihrem code.
Gibt es viele problem mit Ihrem code.
Ich hoffe es wird Euch helfen.