Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 使用条件自动填充textformfield控制器_Flutter_Dart_Controller_Textformfield - Fatal编程技术网

Flutter 使用条件自动填充textformfield控制器

Flutter 使用条件自动填充textformfield控制器,flutter,dart,controller,textformfield,Flutter,Dart,Controller,Textformfield,我试图在我的控制器中使用条件创建textformfield。如果字段为空,它将用我准备的自动填充文本填充。如何在我的textFormField控制器中设置条件? 下面是我的代码 @override void initState() { super.initState(); autofill = new TextEditingController(text: 'auto fill text'); autofill2 = new TextEditingController(text: '

我试图在我的控制器中使用条件创建textformfield。如果字段为空,它将用我准备的自动填充文本填充。如何在我的textFormField控制器中设置条件? 下面是我的代码

@override
void initState() {
  super.initState();
  autofill = new TextEditingController(text: 'auto fill text');
  autofill2 = new TextEditingController(text: 'auto fill text2');
}
这就是变量

final _key = new GlobalKey<FormState>();
TextEditingController autofill;
TextEditingController autofill2;
final first_nameController = TextEditingController();
final last_nameController = TextEditingController();
这是我的API连接器,用于从文本字段保存文本数据

field() async {
String auto= autofill2.text;
String auto2= autofill.text;
String first_name = first_nameController.text;
String last_name = last_nameController.text;
// API URL
final response = await http.post(
  config.baseurl + "autofilltextformfield",
  body: {
    'first_name'.isEmpty ? first_name : auto,
    'last_name'.isEmpty ? last_name : auto2,
  },
);
if (response.statusCode == 200) {
  setState(
    () {
      visible = false;
    },
  );
}
showDialog(
  context: context,
  builder: (BuildContext context) {
    return AlertDialog(
      title: new Text(response.body),
      actions: <Widget>[
        FlatButton(
          child: new Text("OK"),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
      ],
    );
  },
);
}
而不是:

autofill = new TextEditingController(text: 'auto fill text');
autofill2 = new TextEditingController(text: 'auto fill text2');
尝试:

而不是:

autofill = new TextEditingController(text: 'auto fill text');
autofill2 = new TextEditingController(text: 'auto fill text2');
尝试:

autofill = new TextEditingController(text: 'auto fill text');
autofill2 = new TextEditingController(text: 'auto fill text2');
first_nameController.text = 'auto fill text';
last_nameController.text = 'auto fill text2';