Ahmad Zaklouta
Ahmad Zaklouta

Reputation: 183

what to put after return in flutter widget if I have nothing to return

I have a stream from Bluetooth and I want to extract the data and send it to another widget but I am having a problem with the return of the widget. this is my code.

StreamBuilder<List<int>>(
    stream: stream,
    builder: (BuildContext context, AsyncSnapshot<List<int>> snapshot) {
      if (snapshot.hasError) {
        return Text('Error: ${snapshot.error}');
      }
      if (snapshot.connectionState == ConnectionState.active) {
        // geting data from bluetooth
        var currentValue = _dataParser(snapshot.data);
        if (currentValue != "nan") {
          return temperature = double.parse('${currentValue}');
        }
      }
    });

@override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: const [
        Text('Temperature:'),
        Text('20'),  // I want temperature here
      ],
    );
  }

I want to pass temperature to be written instead of 20 in the Text widget.

what shall I put after return?

Upvotes: 0

Views: 54

Answers (1)

Dcow
Dcow

Reputation: 1463

  • Empty SizedBox widget is just fine in that case.
  • There is nil package also, if you okay with using some extras here.
  • Showing some loading state also is a good option

Upvotes: 2

Related Questions