英文:
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),
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论