Как можно уменьшить ширину RaisedButton внутри ListView.builder?

Я не могу понять, как уменьшить ширину 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, но кажется, что элементы ListView.builder постоянно используют максимальную ширину. Как я могу переопределить это?

Спасибо!

13
0
2 351
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 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: () {},
                      ),
                    ),
                  ),
                );

именно то, что я искал!

Hoon 19.05.2020 23:49

старый, но не устаревший, спасибо!

Wenhui Luo 20.12.2021 04:24

Другие вопросы по теме