skip to Main Content

I have a function which loads data to TextFormField from firebase .
can we supply controller to the TextFormField created by following function.

 loadDataToTextFormField(
      QuerySnapshot mySnapshot,
      int index,
      String databaseField,
      String? bulletsAndNumberingType,
      TextStyle textStyle) {
    List getDataList = List.from(mySnapshot.docs[index][databaseField]);
    return Column(
      children: [
        for (var i in getDataList)
          Align(
            alignment: Alignment.centerLeft,
            child: TextFormField(
                //  controller: ?? how to supply controller here,
                initialValue:
                    "$bulletsAndNumberingType  $i", 
                style: (textStyle)
                ),
          ),
      ],
    );
  }
}

Any Help would be highly appriciated.
Thanks

2

Answers


  1. Chosen as BEST ANSWER

    Sorry i forgot TextFormField can't have both properties controller or 'initialValue' at oncce. It can have either controller or 'initialValue'.


  2. You can supply controller to the TextFormField by use following function.

    loadDataToTextFormField(
          QuerySnapshot mySnapshot,
          int index,
          String databaseField,
          String? bulletsAndNumberingType,
          TextStyle textStyle) {
        List getDataList = List.from(mySnapshot.docs[index][databaseField]);
        List<TextEditingController> textEditingControllerList =
            List<TextEditingController>.filled(
                getDataList.length, TextEditingController());
    
        return Column(
          children: [
            for (var i in getDataList)
              Align(
                alignment: Alignment.centerLeft,
                child: TextFormField(
                    controller: textEditingControllerList[i],
                    initialValue: "$bulletsAndNumberingType  $i",
                    style: (textStyle)),
              ),
          ],
        );
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search