如何在同一页面上使用2个不同的小部件?我想在输入时显示内容。
仅当我将其分配给其他变量时才有效,但是我可以使用controller.text并避免创建不必要的变量和应用SetState吗?
Widget _price() {
return ListTile(
leading: Icon(Icons.attach_money),
title: TextFormField(
controller: _priceController,
decoration: InputDecoration(hintText: translate('rent.buy_price')),
maxLength: 5,
keyboardType: TextInputType.number,
validator: (value) {
if (value.isEmpty || value == ' ' || value == '') {
return translate('fill_field');
}
return null;
},
onChanged: (String newPrice) {
print(_priceController.text); // I get the correct value
// also tried SetState() here but doesn't work
},
),
);
}
答案 0 :(得分:0)
您可以使用TextEditingController
的{{1}}函数来调用onChanged
来实时设置其他窗口小部件的文本。
setState(() {})