title: How to calculate with TextEditingControllers in flutter?
body: <p>So in flutter I have <strong>auto-calculated text fields</strong> and I want to calculate a result using a formula.</p>
  <p>Let me first show what I am doing:</p>
  <p><a href="https://i.stack.imgur.com/jy6Vl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jy6Vl.png" alt="enter image description here" /></a></p>
  <p><em>These are those text fields.</em></p>
  <p>The code for these fields:</p>
  <pre><code>enum UnitType {
    meter,
    centimeter,
    feet,
    kilogram,
    gram,
  }
  
  class Units extends StatefulWidget {
    const Units({Key? key}) : super(key: key);
  
    @override
    State&lt;Units&gt; createState() =&gt; _UnitsState();
  }
  
  class _UnitsState extends State&lt;Units&gt; {
    final TextEditingController _feetController = TextEditingController();
  
    final TextEditingController _centimeterController = TextEditingController();
  
    final TextEditingController _meterController = TextEditingController();
  
    final TextEditingController _kilogramController = TextEditingController();
  
    final TextEditingController _gramController = TextEditingController();
  
    void _convertUnit(UnitType type) {
      double? ft = double.tryParse(_feetController.value.text) ?? 0;
      double? cm = double.tryParse(_centimeterController.value.text) ?? 0;
      double? m = double.tryParse(_meterController.value.text) ?? 0;
      double? kg = double.tryParse(_kilogramController.value.text) ?? 0;
      double? g = double.tryParse(_gramController.value.text) ?? 0;
  
      switch (type) {
        case UnitType.feet:
          _meterController.text = (ft / 3.281).toStringAsFixed(2);
          _centimeterController.text = (ft * 30.48).toStringAsFixed(2);
          break;
        case UnitType.meter:
          _centimeterController.text = (m * 100).toStringAsFixed(2);
          _feetController.text = (m * 3.281).toStringAsFixed(2);
          break;
        case UnitType.centimeter:
          _meterController.text = (cm / 100).toStringAsFixed(2);
          _feetController.text = (cm / 30.48).toStringAsFixed(2);
          break;
        case UnitType.kilogram:
          _gramController.text = (kg * 1000).toStringAsFixed(2);
          break;
        case UnitType.gram:
          _kilogramController.text = (g / 1000).toStringAsFixed(2);
          break;
      }
    }
  </code></pre>
  <p>The <strong>formula of BMI(body mass index)</strong> is <code>Kg/m^2</code></p>
  <p><a href="https://i.stack.imgur.com/MeDQG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MeDQG.png" alt="enter image description here" /></a></p>
  <p>Now I want when I click the <strong>BMI button</strong> I want the result to be displayed in the adjacent text field. The <code>formula</code> is <code>BMI = Kilogram/(meter*meter)</code>.</p>
  <p>I couldn't come up with any idea or code. Please help me out with some code to achieve my desired result.</p>