What is the best way to set an array of TextEditingController in a flutter . I mean I need to get a value array of Textfield(1 to n) value and sent to the server.
Can anyone help how to achieve this?
I tried
for(int i=1;i<75;i++) {
TextEditingController _controller[i] = TextEditingController();
}
Regards, Sathish
There are plenty of ways to do that
List<TextEditingController> _controller = List.generate(74, (i) => TextEditingController());
or
List<TextEditingController> _controller = [];
for (int i = 1; i < 75; i++) _controller.add(TextEditingController());
or
List<TextEditingController> _controller = [
for (int i = 1; i < 75; i++)
TextEditingController()
];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With