我在订购页面应用程序的颤动中遇到了一个问题,当我在数量文本字段中输入数字时,会给我一个错误的方向, 例如,当我输入2000时,它会给我0002 我不知道这是什么原因,可能是因为它将_qty标识为文本,但是再一次,它的计算正确,我也已经在其中进行了文本对齐和TextDirections,但是不幸的是,所有操作均失败了, 所以我不知道这是什么原因或如何解决 这些是我的家庭班的代码: 这是代码:
```import 'package:flutter/material.dart';
class Home extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return new _HomeState();
}
}
class _HomeState extends State<Home> {
int radiogroup = 0;
String userinfo = '';
int qty = 0;
String txt = '';
final TextEditingController _qty = new TextEditingController();
void totalprice(String orderprice, int deliveryprice) {
if (orderprice.isNotEmpty && int.parse(orderprice) > 0) {
int totalprice = int.parse(orderprice) * deliveryprice;
setState(() {
txt = 'your order price is \$$totalprice';
});
} else {
setState(() {
txt = "please enter a valid qty and item";
});
}
}
void radiogroupeventhandler(value) {
setState(() {
radiogroup = value;
switch (radiogroup) {
case 0:
totalprice(_qty.text, 1200);
break;
case 1:
totalprice(_qty.text, 3200);
break;
case 2:
totalprice(_qty.text, 4200);
break;
case 3:
totalprice(_qty.text, 6200);
break;
}
});
print(radiogroup);
}
void radiogroupeventhandler2(value) {
setState(() {
_qty.text = value;
switch (radiogroup) {
case 0:
totalprice(_qty.text, 1200);
break;
case 1:
totalprice(_qty.text, 3200);
break;
case 2:
totalprice(_qty.text, 4200);
break;
case 3:
totalprice(_qty.text, 6200);
break;
}
});
print(radiogroup);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Center(child: new Text("Order page"))),
body: new Container(
padding: EdgeInsets.all(22.4),
alignment: Alignment.center,
child: new ListView(
children: <Widget>[
new Image.asset(
'img/user.jpg',
height: 100.0,
width: 100.0,
),
new Container(
padding: EdgeInsets.all(33.4),
child: new Column(
children: <Widget>[
new Text("please make your order !"),
new TextField(
controller: _qty,
textAlign: TextAlign.end,
textDirection: TextDirection.ltr,
keyboardType: TextInputType.number,
onChanged: radiogroupeventhandler2,
decoration: InputDecoration(
hintText: "please enter you identified quantity",
labelText: "QTY",
icon: new Icon(Icons.shopping_cart)),
),
new Padding(padding: EdgeInsets.all(22.0)),
new RadioListTile(
value: 0,
groupValue: radiogroup,
onChanged: radiogroupeventhandler,
title: new Text("pizza king"),
subtitle: new Text("pizza king fast food"),
),
new RadioListTile(
value: 1,
groupValue: radiogroup,
onChanged: radiogroupeventhandler,
title: new Text("Burger king"),
subtitle: new Text("Burger king fast food"),
),
new RadioListTile(
value: 2,
groupValue: radiogroup,
onChanged: radiogroupeventhandler,
title: new Text("MacDonalds"),
subtitle: new Text("MchDonals burger fast food"),
),
new RadioListTile(
value: 3,
groupValue: radiogroup,
onChanged: radiogroupeventhandler,
title: new Text("KFC"),
subtitle: new Text("KFC chicken fast food"),
),
new Text('$txt')
],
))
],
),
),
);
}
}```
答案 0 :(得分:1)
_qty.text = value
尝试在setState之后删除此行。