firebase 在FirestoreListView Flutter中添加固定元素

6ojccjat  于 2023-04-22  发布在  Flutter
关注(0)|答案(1)|浏览(145)

我使用firebase_ui_firestore包。我想设置一个横幅(固定元素)到下面列表的第一项。没有索引选项。因此,我不知道它。
下面是我的代码

FirestoreListView<Map<String, dynamic>>(
                pageSize: 4,
                query: usersQuery,
                itemBuilder: (context, snapshot) {
                  Map<String, dynamic> user = snapshot.data();
                  return FeedBox(
                    imageUrl: user['imageUrl'],
                    displayName: user['displayName'],
                  );
                },
              )
pieyvz9o

pieyvz9o1#

终于找到了

FirestoreQueryBuilder<Map<String, dynamic>>(
                query: usersQuery,
                builder: (context, snapshot, _) {
                  // ...
                  return ListView.builder(
                    itemCount: snapshot.docs.length +1,
                    itemBuilder: (context, index) {
                      // if we reached the end of the currently obtained items, we try to
                      // obtain more items
                      if (snapshot.hasMore &&
                          index + 1 == snapshot.docs.length) {
                        // Tell FirestoreQueryBuilder to try to obtain more items.
                        // It is safe to call this function from within the build method.
                        snapshot.fetchMore();
                      }
                      if (index == 0) {
                        return Container(
                          color: Colors.red,
                          height: 100,
                        );
                      } else {
                        final user = snapshot.docs[index -1].data();
                        return FeedBox(
                          imageUrl: user['imageUrl'],
                        );
                      }
                    },
                  );
                },
              )

相关问题