无法减小ListView.builder项目的宽度。

huangapple go评论67阅读模式
英文:

Can't decrease the width of ListView.builder Item

问题

我需要减小ListView中每个项目的宽度,但它似乎不遵守...我知道可以通过添加一些填充来实现,但是否有其他方法?我尝试过BoxConstraints、Container.width、SizedBox...

return ListView.builder(
    shrinkWrap: true,
    itemCount: snapshot.data!.length,
    itemBuilder: (context, index) {
        return Padding(
            padding: const EdgeInsets.only(bottom: 28),
            child: Container(
                width: 120, //在这里尝试...
                constraints: BoxConstraints(
                    minWidth: 120, maxWidth: 120), //在这里尝试...
                decoration: BoxDecoration(
                    border: (currentCustomerId ==
                            snapshot.data?[index].id)
                        ? Border.all(
                            color: const Color.fromRGBO(
                                141, 195, 119, 1),
                            width: 3,
                        )
                        : null),
                child: InkWell(
                    onTap: () {
                    },
                    child: Container(
                        height: 116,
                        width: 120,
                        constraints: BoxConstraints(
                            minWidth: 120, maxWidth: 120), //在这里尝试..
                        color: Colors.black,
                        child: Image.network(
                            snapshot.data?[index].marina
                                    ?.logoAppFile ??
                                '',
                            fit: BoxFit.contain,
                        ),
                    ),
                ),
            ),
        );
    });
英文:

I need to decrease the width of each item from a ListView, and It simply won't obey... I know I can do it by adding some padding, but is there any other way?? I've tried BoxConstraints, Container.width, SizedBox,...

return ListView.builder(
    shrinkWrap: true,
    itemCount: snapshot.data!.length,
    itemBuilder: (contenxt, index) {
      return Padding(
        padding: const EdgeInsets.only(bottom: 28),
        child: Container(
          width: 120, //Tried here...
          constraints: BoxConstraints(
              minWidth: 120, maxWidth: 120), //Tried here...
          decoration: BoxDecoration(
              border: (currentCustomerId ==
                      snapshot.data?[index].id)
                  ? Border.all(
                      color: const Color.fromRGBO(
                          141, 195, 119, 1),
                      width: 3,
                    )
                  : null),
          child: InkWell(
            onTap: () {
            },
            child: Container(
              height: 116,
              width: 120,
              constraints: BoxConstraints(
                 minWidth: 120, maxWidth: 120), //Tried here..
              color: Colors.black,
              child: Image.network(
                snapshot.data?[index].marina
                        ?.logoAppFile ??
                    '',
                fit: BoxFit.contain,
              ),
            ),
          ),
        ),
      );
    });

答案1

得分: 0

尝试使用另一个小部件包装 Padding 小部件,约束减小,大小增加在 Flutter 中。

itemBuilder: (contenxt, index) {
  return Align( // 可以提供您喜欢的对齐方式,它可以
    child: Padding(
      padding: const EdgeInsets.only(bottom: 28),
英文:

Try to wrap the Padding widget with another widget, constraints goes down, size goes up on flutter

itemBuilder: (contenxt, index) {
  return Align( // you can provide alginment the one you like , it can 
    child: Padding(
      padding: const EdgeInsets.only(bottom: 28),

huangapple
  • 本文由 发表于 2023年3月4日 02:57:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75630893.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定