【问题标题】:Exception was thrown: FormatException: Invalid radix-10 number抛出异常:FormatException: Invalid radix-10 number
【发布时间】:2018-12-29 18:31:47
【问题描述】:

尝试从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);
                }
              })
        ],
      );
    });
  }

【问题讨论】:

    标签: dart flutter radix


    【解决方案1】:

    这个错误很愚蠢。 ?‍♀️ 我没有将控制器转换为文本。我直接从控制器 ==> 字符串。我保留这个问题,以防其他人有类似的疑问。 ?

    【讨论】:

      猜你喜欢
      • 2019-08-19
      • 1970-01-01
      • 2020-05-08
      • 1970-01-01
      • 2021-05-30
      • 2021-04-07
      • 2021-06-11
      • 1970-01-01
      • 2013-06-23
      相关资源
      最近更新 更多