'Access Element in List by Index

I'm getting this error while trying to access element in a List .

This is my code :

List<TextEditingController> controllers = [];

void _addCardWidgetExp() {
setState(() {
  widget.controllers.add(TextEditingController());
  widget.controllers.add(TextEditingController());
  widget.controllers.add(TextEditingController());
  widget.controllers.add(TextEditingController());

 

  _cardList.add(SizedBox(height: 10));
  Divider(
    thickness: 2,
    color: Colors.white,
  );
  _cardList.add(InputRefNomProduit(
    fieldController: widget.controllers.first,
    fieldController2: widget.controllers.[1],
    fieldController3: widget.controllers.[2],
    fieldController4: widget.controllers.last,
  ));
});

}

I'm getting the following error :

    The getter '[' isn't defined for the type 'List<TextEditingController>'.
Try importing the library that defines '[', correcting the name to the name of an existing getter, or defining a getter or field named '['.

ps: the error is only on these two lines :

fieldController2: widget.controllers.[1],
    fieldController3: widget.controllers.[2],


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source