控制器:
List<TextEditingController> areaController = [];
代码:
Column(
children: [
ListView.builder(
shrinkWrap: true,
itemCount: 5,
itemBuilder: (context, index) {
areaController.add(TextEditingController());
return TextField(
controller: areaController[index],
keyboardType: TextInputType.number,
onChanged: (text) {},
decoration: const InputDecoration(
labelText: "Area",
),
);
},
),
const SizedBox(
height: 30,
),
ElevatedButton(
child: const Text('Submit'),
onPressed: () {
//get the value of every index textfield
},
),
],
),
如何在Listview
中设置flutter textfield
并在提交时获取每个textfield
的值
1条答案
按热度按时间u0sqgete1#
你为什么不用
for
环?只需在每个TextField
上调用.text
来获取文本值。