我似乎不知道如何在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])),
                      ),
                    );
                  },
                ),
              ),
            );
          }),

我明白了:

enter image description here

我试图缩小RaisedButton的宽度,但似乎ListView.builder个项目都设置为使用最大宽度.我怎么能推翻它?

谢谢!

推荐答案

如果您想要RaisedButton的默认大小,只需将Align小部件添加为父级即可

    return Container(
                  margin: EdgeInsets.symmetric(horizontal: 30),
                  padding: itemEdges,
                  child: Align(
                      child: RaisedButton(
                        child: Text("index: $index"),
                        onPressed: () {},

                    ),
                  ),
                );

如果您想更改大小,请使用Align内的SizedBox

    return Container(
                  margin: EdgeInsets.symmetric(horizontal: 30),
                  padding: itemEdges,
                  child: Align(
                    child: SizedBox(
                      width: 250,
                      child: RaisedButton(
                        child: Text("index: $index"),
                        onPressed: () {},
                      ),
                    ),
                  ),
                );

Dart相关问答推荐

从扩展类访问抽象类属性

当 ng-repeat 嵌套在 AngularDart 中时访问外部 $index

Flutter:Firebase 基本查询或基本搜索代码

GPS是否激活

使用 headers 和 body 进行 HTTP Post

了解Dart private class

Flutter 以编程方式触发 FutureBuilder

如何在Flatter中设置特定容器中所有文本的 colored颜色 ?

Flutter SlideTransition 从 Offset OFF SCREEN 开始

将DateTime转换为ISO 8601

如何将条目添加到列表中的特定索引?

您可以将命名参数与简写构造函数参数结合起来吗?

带范围的dartswitch

在我的 angular-cli 元素中从 node-sass 切换到 dart sass

学习 Dart 好还是我必须使用基本的 javascript?

Dart 中的 Math.round() 在哪里?

有没有办法在 Dart 中通过引用传递原始参数?

Dart中var和dynamic类型的区别?

Dart 空值判断习惯用法或最佳实践是什么?

Dart 如何获取枚举的value