title: Why did If statement dispose TextFormField in flutter?
body: <p>In my app I need to preview a table which appear if the user entered some data. So I added a if statement. There is a button to clear the form too. My TextFormField is placed under the table. It won't get disposed until I clear the form. But after I clear the form it get disposed. I added another TextFormField beneath the table to check whether the table is causing the error. That TextFormField also got disposed. Why is this happening?</p>
  <pre><code>// This is the code of the Table
  if (_data.length != 0)
        Row(children: [
          Expanded(
              child: Padding(
                  padding: EdgeInsets.only(top: 15, bottom: 10),
                  child: DataTable(
                    columnSpacing: 20,
                    columns: const &lt;DataColumn&gt;[
                      DataColumn(label: Center(child: Text('Medications'))),
                      DataColumn(label: Center(child: Text('Amount'))),
                      DataColumn(label: Center(child: Text('Days'))),
                      DataColumn(label: Center(child: Text('When'))),
                      DataColumn(
                          label: Text(
                        '-',
                        style: TextStyle(fontSize: 22),
                        textAlign: TextAlign.center,
                      ))
                    ],
                    rows: _data
                        .map(
                          ((element) =&gt; DataRow(
                                cells: [
                                  (DataCell(Text(element[&quot;drug&quot;]))),
                                  DataCell(Text(element[&quot;amount&quot;].toString(),
                                      textAlign: TextAlign.center)),
                                  DataCell(Text(element[&quot;days&quot;].toString(),
                                      textAlign: TextAlign.center)),
                                  DataCell(Text(element[&quot;when&quot;],
                                      textAlign: TextAlign.center)),
                                  DataCell(RButton(
                                    onPressed: onPressedDrugs,
                                    text: element[&quot;drug&quot;],
                                  ))
                                ],
                              )),
                        )
                        .toList(),
                  )))
        ]),
      // This is the code of the TextFormField
      Padding(
        padding: EdgeInsets.symmetric(horizontal: 12, vertical: 10),
        child: Row(
          children: [
            Expanded(
              child: TextFieldSearch(
                controller: controllerInvestigation,
                initialList: allInvestigations,
                label: &quot;Enter the Investigation&quot;,
                decoration: InputDecoration(
                  focusColor: Colors.purple,
                  border: OutlineInputBorder(),
                  labelText: &quot;Enter the Investigation&quot;,
                  icon: FaIcon(FontAwesomeIcons.vial),
                ),
              ),
            ),
            PopupMenuButton&lt;String&gt;(
                elevation: 16,
                icon: Icon(Icons.arrow_drop_down),
                itemBuilder: (context) =&gt;
                    List&lt;String&gt;.from(starInvestigations)
                        .map&lt;PopupMenuItem&lt;String&gt;&gt;((String value) {
                      return PopupMenuItem&lt;String&gt;(
                          value: value,
                          child: Container(
                              color: Colors.transparent,
                              width: double.infinity,
                              child: TextButton(
                                child: ListTile(
                                    title: Text(value,
                                        textAlign: TextAlign.left)),
                                onPressed: () {
                                  setState(() {
                                    controllerInvestigation.text = value;
                                  });
                                  Navigator.pop(context);
                                },
                              )));
                    }).toList()),
          ],
        ),
      ),
  
         // This is the code of the Clear button
          Padding(
              padding: EdgeInsets.symmetric(
                  horizontal:
                      (MediaQuery.of(context).size.width / 2 - 150) / 2,
                  vertical: 10),
              child: SizedBox(
                width: 150,
                child: FloatingActionButton.extended(
                  onPressed: () {
                    controllerName.text = '';
                    controllerAmount.text = '';
                    controllerDrug.text = '';
                    controllerAgeYears.text = '';
                    controllerDays.text = '';
                    controllerAgeMonths.text = '';
                    controllerInvestigation.text = '';
                    controllerSystolicPressure.text = '';
                    controllerDiastolicPressure.text = '';
                    controllerComplain.text = '';
                    _isSelected = [false, false];
                    setState(() {
                      _data = [];
                      selectedInvestigations = [];
                      getData();
                    });
                  },
                  focusColor: Colors.cyan[400],
                  label: const Text('Clear  '),
                  icon: const Icon(Icons.clear_all),
                  backgroundColor: Colors.cyan[300],
                ),
              )),
  </code></pre>