我似乎无法弄清楚如何减小RaisedButton
内ListView.builder
的宽度。
ListView.builder(
itemCount: streetList.length,
itemBuilder: (context, index) {
bool first = 0 == (index);
bool last = streetList.length - 1 == (index);
EdgeInsets itemEdges = EdgeInsets.only(bottom: 20);
if (first) {
itemEdges = EdgeInsets.only(top: 50, bottom: 20);
} else if (last) {
itemEdges = EdgeInsets.only(bottom: 50);
}
return Container(
margin: EdgeInsets.symmetric(horizontal: 30),
padding: itemEdges,
child: SizedBox(
// height: 50,
child: RaisedButton(
child: Text(streetList[index]),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => StreetNumberList(
widget.peopleList, (streetList[index])),
),
);
},
),
),
);
}),
我明白了:
我正在尝试减小RaisedButton
的宽度,但似乎ListView.builder
项始终设置为使用最大宽度。我该如何覆盖?
谢谢!
答案 0 :(得分:1)
如果您想使用RaisedButton
的默认大小,只需将Align
小部件添加为父级
return Container(
margin: EdgeInsets.symmetric(horizontal: 30),
padding: itemEdges,
child: Align(
child: RaisedButton(
child: Text("index: $index"),
onPressed: () {},
),
),
);
如果要更改大小,请在SizedBox
内使用Align
return Container(
margin: EdgeInsets.symmetric(horizontal: 30),
padding: itemEdges,
child: Align(
child: SizedBox(
width: 250,
child: RaisedButton(
child: Text("index: $index"),
onPressed: () {},
),
),
),
);