gpt4 book ai didi

flutter : Card with Gridview

转载 作者:行者123 更新时间:2023-12-05 01:55:58 28 4
gpt4 key购买 nike

我是 Flutter 的新手,我想做这个设计,我花了一段时间才找到要使用的东西,但每次我尝试编写代码并使用 Listview 时,它都会给我错误,或者卡片不与 Gridview 对齐。

Image

最佳答案

试试下面的代码希望对你有帮助。引用GridView here

   Center(
child: GridView.builder(
shrinkWrap: true,
padding: const EdgeInsets.symmetric(horizontal: 30),
itemCount: 4,
itemBuilder: (ctx, i) {
return Card(
child: Container(
height: 290,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20)),
margin: EdgeInsets.all(5),
padding: EdgeInsets.all(5),
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: Image.network(
'https://tech.pelmorex.com/wp-content/uploads/2020/10/flutter.png',
fit: BoxFit.fill,
),
),
Text(
'Title',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
Row(
children: [
Text(
'Subtitle',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
],
)
],
),
],
),
),
);
},
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 1.0,
crossAxisSpacing: 0.0,
mainAxisSpacing: 5,
mainAxisExtent: 264,
),
),
),

您的结果屏幕-> output

关于 flutter : Card with Gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70015558/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com