Flutter : multi cursor of TextEditingController in an ExpansionTile widget

Issue

I Have couple of TextEditingControllers in an ExpansionTile.

When i click on one of them, I get multi cursor on all of the TextEditingController with it.

When i put a text in one the TextEditingController (or any action) : it affect all of the other Text in the same ExpansionTile widget.

enter image description here

    widget build(){
               ...
               ...
    
               ExpansionTile(
                              title: Container(
                                  width: double.infinity,
    
                                  child: Text("Parametre vitaux",
                                    style: TextStyle(fontSize: 18),)),
                              trailing: Icon(Icons.arrow_drop_down, size: 32,
                                color: Colors.black,),
                              onExpansionChanged: (value) {
                                setState(() {
                                  // isExpand=value;
                                });
                              },
    
                              children: [
                                listmesures()
    
                              ]
                          )
    }

      Widget listmesures() {
        return Container(child:
        ListView(
          shrinkWrap: true,
          scrollDirection: Axis.vertical,
    
          children: [
            TextFormField(
              keyboardType: TextInputType.phone,
              focusNode: f2,
              controller: _poidsController,
              style: GoogleFonts.lato(
                  fontSize: 18, fontWeight: FontWeight.bold),
              decoration: InputDecoration(
                contentPadding:
                EdgeInsets.only(left: 20, top: 10, bottom: 10),
                border: OutlineInputBorder(
                  borderRadius:
                  BorderRadius.all(Radius.circular(90.0)),
                  borderSide: BorderSide.none,
                ),
                filled: true,
                fillColor: Colors.grey[350],
                hintText: 'Poids Kg*',
                hintStyle: GoogleFonts.lato(
                  color: Colors.black26,
                  fontSize: 18,
                  fontWeight: FontWeight.w800,
                ),
              ),
              validator: (value) {
                if (value.isEmpty) {
                  return 'entrez poids';
                }
                return null;
              },
              onFieldSubmitted: (String value) {
                f2.unfocus();
                FocusScope.of(context).requestFocus(f3);
              },
              textInputAction: TextInputAction.next,
            ),
    
            SizedBox(
              height: 10,
            ),
    
            TextFormField(
              keyboardType: TextInputType.phone,
              focusNode: f2,
              controller: _tempController,
              style: GoogleFonts.lato(
                  fontSize: 18, fontWeight: FontWeight.bold),
              decoration: InputDecoration(
                contentPadding:
                EdgeInsets.only(left: 20, top: 10, bottom: 10),
                border: OutlineInputBorder(
                  borderRadius:
                  BorderRadius.all(Radius.circular(90.0)),
                  borderSide: BorderSide.none,
                ),
                filled: true,
                fillColor: Colors.grey[350],
                hintText: 'Temperature*',
                hintStyle: GoogleFonts.lato(
                  color: Colors.black26,
                  fontSize: 18,
                  fontWeight: FontWeight.w800,
                ),
              ),
              validator: (value) {
                if (value.isEmpty) {
                  return 'entrez temperature';
                }
                return null;
              },
              onFieldSubmitted: (String value) {
                f2.unfocus();
                FocusScope.of(context).requestFocus(f3);
              },
              textInputAction: TextInputAction.next,
            ),
           .....
    
          ],
        ));
      }

ExpansionTile: It is a simple and useful widget. This widget lets you create a collapse or expansion view with features similar to ListTile. It is like a ListTile which will expand on tapping the title.

TextEditingController : Connect the TextEditingController to a text field.

Solution

I’ve solved using different focusNode.

Answered By – Ayoub Arroub

Answer Checked By – Timothy Miller (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.