Я не могу понять, как уменьшить ширину 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
постоянно используют максимальную ширину. Как я могу переопределить это?
Спасибо!
Если вам нужен размер 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: () {},
),
),
),
);
старый, но не устаревший, спасибо!
именно то, что я искал!