title: How to fix invalid double in Flutter
body: <p>I have data coming from ESP32 in this format: number,number,number and I am trying to print it in text in flutter but I am getting invalid double.</p>
  <p>I really read the other answers but could not figure it out. this is my code:</p>
  <pre><code>String _dataParser(List&lt;int&gt; dataFromDevice) {
      return utf8.decode(dataFromDevice);
  }
  
  @override
  Widget build(BuildContext context) {
      return Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [
              Expanded(
                  flex: 2,
                  child: StreamBuilder&lt;List&lt;int&gt;&gt;(  **// I am getting the error here**
                      stream: stream,
                      builder:(BuildContext context, AsyncSnapshot&lt;List&lt;int&gt;&gt; snapshot) {
                          if (snapshot.connectionState == ConnectionState.waiting) {
                              return const CircularProgressIndicator();
                          } else if (snapshot.connectionState == ConnectionState.active ||
                                     snapshot.connectionState == ConnectionState.done) {
                              if (snapshot.hasError) {
                                  temperature = -1;
                                  speed = -1;
                                  pressure = -1;
                                  flow = -1;
                              }
                              if (snapshot.hasData) {
                                  var currentValue = _dataParser(snapshot.data);
                                  var sensorData = currentValue.split(&quot;,&quot;);
                                  // get the temperature
                                  if (sensorData[0] == &quot;nan&quot;) {
                                    temperature = -2;
                                  }
                                  temperature = double.parse('$sensorData[0]');
                                  // get the speed
                                  if (sensorData[1] == &quot;nan&quot;) {
                                    speed = -2;
                                  }
                                  speed = double.parse('$sensorData[1]');
                                  // get the pressure
                                  if (sensorData[2] == &quot;nan&quot;) {
                                    pressure = -2;
                                  }
                                  pressure = double.parse('$sensorData[2]');
                              } else {
                                  temperature = -3;
                                  speed = -3;
                                  pressure = -3;
                                  flow = -3;
                              }
                          }
                          return Row(
                              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                              children: [
                                  Column(
                                      children: [
                                          const Text('Temperature'),
                                          Text('$temperature'),
                                      ],
                                  ),
                                  Column(
                                      children: [
                                          const Text('Speed'),
                                          Text('$speed'),
                                      ],
                                  ),
                                  Column(
                                      children: [
                                          const Text('Pressure'),
                                          Text('$pressure'),
                                    ] ,
                                  ),
                                  Column(
                                      children: [
                                          const Text('Flow'),
                                          Text('$flow'),
                                      ],
                                  ),
                              ],
                          );
                      }
                  ),
              ),
          ],
      );
  }
  </code></pre>
  <p>the problem is with this line:</p>
  <blockquote>
  <p>temperature = double.parse('$sensorData[0]');</p>
  </blockquote>
  <p>the exception is:</p>
  <blockquote>
  <p>════════ Exception caught by widgets library
  ═══════════════════════════════════
  The following FormatException was
  thrown building StreamBuilder&lt;List&gt;(dirty, state:
  _StreamBuilderBaseState&lt;List, AsyncSnapshot&lt;List&gt;&gt;#67513): Invalid double [][0] The relevant error-causing widget was
  StreamBuilder&lt;List&gt; lib\componants\device_data.dart:139 When the
  exception was thrown, this was the stack
  #0      double.parse (dart:core-patch/double_patch.dart:111:28)
  #1      _DeviceDataState.build. lib\componants\device_data.dart:160</p>
  </blockquote>
  <p>the value for currentValue and sensorData when the app start is as follow:</p>
  <p>I/flutter (25023): currentValue</p>
  <p>I/flutter (25023):</p>
  <p>I/flutter (25023): sensorData</p>
  <p>I/flutter (25023): [ ]</p>
  <p>and then when the app is connected to ESP32 is as follow:</p>
  <p>I/flutter (25023): current</p>
  <p>I/flutter (25023): 363.00,363.00,363.00</p>
  <p>I/flutter (25023): sensor</p>
  <p>I/flutter (25023): [363.00, 363.00, 363.00]</p>
  <p>so the invalid double is only in the beginning.</p>