当尝试从TextFormFeild
获取整数时出现此错误。我已多次使用此小部件,但始终没有收到此错误。有人知道这到底意味着什么吗?
这将是很大的帮助。以下只是整个(1084行)代码的一部分,我认为该错误可能是:
(还初始化了controller:'bowlerIndexController = new TextEditingController(text: "");'
:/)。...
void changeBowler(BuildContext context) {
showDialog(
context: context,
builder: (context) {
return new SimpleDialog(
title: new Text("Who is bowling next?",
style:
new TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold)),
children: <Widget>[
new Column(
children: List<Widget>.generate(teamBowling.length, (index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: new Row(
children: <Widget>[
new Padding(
padding: new EdgeInsets.all(2.0),
child: new Text(
(index + 1).toString(),
style: new TextStyle(fontSize: 15.0),
),
),
new Text(teamBowling[index].player["Name"],
style: new TextStyle(
fontSize: 18.0, fontWeight: FontWeight.bold))
],
),
);
}),
),
new TextFormField(
keyboardType: new TextInputType.numberWithOptions(
signed: false, decimal: false),
decoration: new InputDecoration(
hintText: "Enter the bowler's corresponding number"),
controller: bowlerIndexController,
),
new RaisedButton(
child: new Text(
"DONE",
style: new TextStyle(color: Colors.black),
),
onPressed: () {
int a =
int.parse(bowlerIndexController.text.toString()) - 2;
if (a >= 0 && a < teamBowling.length) {
bowlerIndex = int.parse(bowlerIndexController.toString());
Navigator.pop(context);
}
})
],
);
});
}
答案 0 :(得分:3)
错误很愚蠢:/。我没有将控制器转换为文本。我直接从控制器==>字符串做了。我保留这个问题,以防其他人有类似的查询:P。