gpt4 book ai didi

flutter - 我如何从 TextEditingController 中获取 int 数据

转载 作者:IT王子 更新时间:2023-10-29 07:11:36 27 4
gpt4 key购买 nike

我想在 Flutter 中获取在 TextField() 中输入的 int 数据,我使用 TextEditingController:

TextEditingController _section_id = new TextEditingController();

并在其中使用这个 Controller :

TextField(controller: _section_id,
keyboardType: TextInputType.number,)

但是现在,我怎样才能得到 int 数据呢?我尝试这种方式

Repository().placeAddApiProvider(_section_id.text)

但它只是字符串,并尝试转换为 int,

Repository().placeAddApiProvider(_section_id.text as int)

but it is not work show me this error:
Unhandled Exception: type 'String' is not a subtype of type 'int' in type cast
E/flutter ( 6950): #0 AddPlaceState.build.<anonymous closure> (package:mosul/src/ui/users/add_place.dart:93:50)
E/flutter ( 6950): <asynchronous suspension>
E/flutter ( 6950): #1 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:513:14)
E/flutter ( 6950): #2 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:568:30)
E/flutter ( 6950): #3 GestureRecognizer.invokeCallback (package:flutter/src/gestu...

谢谢

最佳答案

当我们想从 TextEditingController 中获取一个整数时,这样做,

 int var =int.parse(_section_id.text);

关于flutter - 我如何从 TextEditingController 中获取 int 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56207275/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com