我有一个ListView
,并且在它的左侧需要一个扩展的垂直线(请参见下图)。我已经实现了以下布局,但可以扩展到无限。
以下是上述布局的代码:
return Scaffold(
...
body: Column(
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 4.0),
color: Colors.grey,
width: 4.0,
child: SizedBox.expand(),
),
Flexible(
child: StreamBuilder( // Creates the list view
stream: ...,
builder: ...,
),
),
],
),
],
),
};
由于SizedBox.expand()
,行变为无限,但如何适应屏幕。有什么建议吗?
或者有一种方法可以从ListView
项中获得相同的效果(没有固定的大小)。
答案 0 :(得分:2)
如果您只有一个孩子,请不要将“列”用作“父母”,这对我有用:
return Container(
child: Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 4.0),
color: Colors.grey,
width: 4.0,
),
Expanded(
child: ListView.builder(
// Creates the list view
shrinkWrap: true,
itemCount: list.length,
itemBuilder: (context, index) {
return ListTile(
contentPadding: EdgeInsets.all(20.0),
title: Text(list[index].toString()),
);
},
),
),
],
),
);