【问题标题】:set card to Listview将卡片设置为 Listview
【发布时间】:2020-05-26 18:30:57
【问题描述】:

我是新来的颤振。 请帮我解决卡片列表视图。 我正在从 SQLite 获取数据并将其直接设置为 listview。请让我知道如何在我的代码中添加卡。 这是我的代码。

 body: FutureBuilder<List<UserModel>>(
    future: db.getUserModelData(),
    builder: (context, snapshot) {
      if (!snapshot.hasData)
        return Center(child: CircularProgressIndicator());

      return ListView(
        children: snapshot.data
            .map((user) => ListTile(
                  title: Text(user.name),
                  subtitle: Text(user.bDate),
                  leading: CircleAvatar(
                    backgroundColor: Color(
                            (math.Random().nextDouble() * 0xFFFFFF)
                                    .toInt() <<
                                0)
                        .withOpacity(1.0),
                    child: Text(user.name[0],
                        style: TextStyle(
                          fontSize: 18.0,
                          color: Colors.white,
                        )),
                  ),
                ))
            .toList(),
      );
    },
  ),

【问题讨论】:

  • 你能解释一下你需要什么吗?
  • @SelimKundakçıoğlu 我想将卡片添加到我的此列表中

标签: listview flutter dart


【解决方案1】:

我已经用 Column() 解决了我的问题 这是代码

return Column(
            children: List.generate(snapshot.data.length, (itemIndex) {
              ProfileModel product = snapshot.data[itemIndex];
              return Card(
                  child: ListTile(
                leading: SizedBox(
                    height: 50.0,
                    width: 50.0,
                    child: CircleAvatar(
                      backgroundColor: Color(
                              (math.Random().nextDouble() * 0xFFFFFF)
                                      .toInt() <<
                                  0)
                          .withOpacity(1.0),
                      child: Text(product.name[0],
                          style: TextStyle(
                            fontSize: 18.0,
                            color: Colors.white,
                          )),
                    )),
                title: Text(product.name),
                subtitle: Text(product.bDate + ', ' + product.mobile),
              ));
            }),
          );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-02
    • 2015-04-09
    • 2016-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多