title: Calling setState from a child event in flutter?
body: <p>I need to redraw my UI whenever the app receives data from a serial device (using the usb_serial package).</p>
  <pre><code>TextEditingController cntrl = TextEditingController();
  ...
  ListView(
  children:[
                       TextButton(
                          onPressed: () async {
                            port = await _deviceList[0].create();
                            bool? openResult = await port?.open();
                            if (!openResult!) {
                              SmartDialog.showToast(&quot;Failed to connect!&quot;);
                              return;
                            }
                            port?.setPortParameters(
                              globals.baudRate,
                              globals.dataBits,
                              globals.stopBits,
                              globals.parity,
                            );
                            SmartDialog.showToast(&quot;Connected!&quot;);
                            port?.inputStream?.listen((Uint8List event) {
                              setState(() {
                                _cntrl.text=utf8.decode(event);
                              });
                            });
                          },
                          child: const Text(&quot;Start&quot;),
                          style: startButtonStyle,
                        ),
     TextField(
       controller: _cntrl,
     ),
  ],
  )
  </code></pre>
  <p>but the UI is never redrawn. I searched a lot on the web on what should be done if I have to call setState() from a child event but couldn't find any answers. What could be the solution?</p>
  <p><strong>Edit:</strong>
  Apparently it was just some weird bug, I copied the same code to a new project and it started working like a charm.</p>