【问题标题】:Flutter : Card with GridviewFlutter:带有 Gridview 的卡片
【发布时间】:2021-12-29 02:09:14
【问题描述】:

我是新手,我想做这个设计,我需要一段时间才能找到要使用的东西,但是每次我尝试对其进行编码并使用 Listview 时都会出现错误,或者卡片与 Gridview 不对齐。

【问题讨论】:

    标签: flutter gridview flutter-layout


    【解决方案1】:

    试试下面的代码希望对你有帮助。请参考GridViewhere

       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,
                    ),
                  ),
                ),
    

    您的结果屏幕->

    【讨论】:

      【解决方案2】:

      您可以使用 Gridview 并在 Gridview Builder 中返回您自定义样式的卡片,我将构建您所需的设计。

      这里是 GridView 官方文档。 [文档1

      【讨论】:

        猜你喜欢
        • 2020-10-31
        • 2018-12-22
        • 2021-11-20
        • 2019-09-25
        • 2023-03-08
        • 1970-01-01
        • 1970-01-01
        • 2020-07-07
        • 1970-01-01
        相关资源
        最近更新 更多