Flutter 当我调用set State时,其他字段被更新为空白,有没有一种方法可以让TextFormFields赢';当我调用set state时,它不会变为空

Flutter 当我调用set State时,其他字段被更新为空白,有没有一种方法可以让TextFormFields赢';当我调用set state时,它不会变为空,flutter,Flutter,我知道这些字段会被更新为空白,因为我正在调用set state方法,但是如果我没有在我的切换按钮中调用set state方法,则值不会更改 那么,有没有一种方法可以让我使用切换按钮,而不会将TextFormFields更新为空白 这就是值所在的位置 class _AddPostState extends State<AddPost> { List<bool> _typeSelection = [false, false, false]; String title

我知道这些字段会被更新为空白,因为我正在调用set state方法,但是如果我没有在我的切换按钮中调用set state方法,则值不会更改

那么,有没有一种方法可以让我使用切换按钮,而不会将TextFormFields更新为空白

这就是值所在的位置

class _AddPostState extends State<AddPost> {
  List<bool> _typeSelection = [false, false, false];
  String title = "";
  String type = "";
  
这是按钮

ToggleButtons(
                           
                            onPressed: (int newIndex) {
                              if (newIndex == 0) {
                                type = "Dog";
                                print(type);
                              }
                              if (newIndex == 1) {
                                type = "Cat";
                                print(type);
                              }
                              if (newIndex == 2) {
                                type = "Bird";
                                print(type);
                              }
                              setState(() {
                                for (int index = 0;
                                    index < _typeSelection.length;
                                    index++) {
                                  if (index == newIndex) {
                                    _typeSelection[index] = true;
                                  } else {
                                    _typeSelection[index] = false;
                                  }
                                }
                              });
切换按钮(
onPressed:(int newIndex){
如果(newIndex==0){
type=“Dog”;
打印(打印);
}
如果(newIndex==1){
type=“Cat”;
打印(打印);
}
如果(newIndex==2){
type=“Bird”;
打印(打印);
}
设置状态(){
对于(int指数=0;
索引<_typeSelection.length;
索引++){
if(index==newIndex){
_类型选择[索引]=真;
}否则{
_类型选择[索引]=错误;
}
}
});

添加
初始值:键入
作为
TextFormField
的参数,或向其添加
textededitingcontroller
。非常适合我谢谢enzo的回答
ToggleButtons(
                           
                            onPressed: (int newIndex) {
                              if (newIndex == 0) {
                                type = "Dog";
                                print(type);
                              }
                              if (newIndex == 1) {
                                type = "Cat";
                                print(type);
                              }
                              if (newIndex == 2) {
                                type = "Bird";
                                print(type);
                              }
                              setState(() {
                                for (int index = 0;
                                    index < _typeSelection.length;
                                    index++) {
                                  if (index == newIndex) {
                                    _typeSelection[index] = true;
                                  } else {
                                    _typeSelection[index] = false;
                                  }
                                }
                              });