I have this row and it always throws an exception because of ListTile. I understand that I should use expanded but could not figure out where to put it in the StreamBuilder.
Row get upperSection {
return Row(
children: <Widget>[
StreamBuilder<BluetoothDeviceState>(
stream: widget.device.state,
initialData: BluetoothDeviceState.connecting,
builder: (c, snapshot) => ListTile(
leading: (snapshot.data == BluetoothDeviceState.connected)
? const Icon(Icons.bluetooth_connected)
: const Icon(Icons.bluetooth_disabled),
title: Text('Device is ${snapshot.data.toString().split('.')[0]}.'),
subtitle: Text('${widget.device.id}'),
trailing: StreamBuilder<bool>(
//The below stream is to show either a refresh button or
//CircularProgress based on the service discovering status,
//and a IndexedStack widget is used to present the needed widget
stream: widget.device.isDiscoveringServices,
initialData: false,
builder: (c, snapshot) => IndexedStack(
index: snapshot.data ? 0 : 0,
children: <Widget>[
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () => widget.device.discoverServices(),
),
const IconButton(
icon: SizedBox(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation(Colors.grey),
),
width: 17.0,
height: 17.0,
),
onPressed: null,
),
],
),
),
),
),
],
);
}
the exception is:
════════ Exception caught by rendering library ═════════════════════════════════ RenderBox was not laid out: RenderMouseRegion#d2d47 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': package:flutter/…/rendering/box.dart:1 Failed assertion: line 1929 pos 12: 'hasSize'
The relevant error-causing widget was ListTile lib\componants\device_screen_widgets.dart:44
CodePudding user response:
Try this:
Row(
children: <Widget>[
Expanded(
child:StreamBuilder<BluetoothDeviceState>(
stream: widget.device.state,
....
)
)
],
);