Dart 如何减少ListView.builder中升起的按钮的宽度?
我似乎不知道如何减少Dart 如何减少ListView.builder中升起的按钮的宽度?,dart,flutter,Dart,Flutter,我似乎不知道如何减少ListView.builder中RaisedButton的宽度 ListView.builder( itemCount: streetList.length, itemBuilder: (context, index) { bool first = 0 == (index); bool last = streetList.length - 1 == (index);
ListView.builder中RaisedButton
的宽度
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])),
),
);
},
),
),
);
}),
我明白了:
我试图减小raised按钮的宽度,但它看起来像ListView。生成器项设置为始终使用最大宽度。我怎么能推翻这一点
谢谢 如果您想要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: () {},
),
),
),
);
正是我要找的!