简体   繁体   English

Flutter - 我如何查询相同的文档 ID - 在下一页 - 作为先前单击的 ListTile

[英]Flutter - How can i query the same document id - on the next page - as a ListTile that was previously clicked

Basically what i'm saying is - I have a listview.builder and each ListTile displays three fields from a particular document in my firestore collection.基本上我要说的是 - 我有一个 listview.builder 并且每个 ListTile 显示来自我的 firestore 集合中特定文档的三个字段。 What i want to implement is, when that listtile is clicked it should take the user to a page that displays more fields from that same document.我想要实现的是,当单击该 listtile 时,它应该将用户带到一个页面,该页面显示来自同一文档的更多字段。 What i want to know is, What i am supposed to query and how can i get the exact same document id.我想知道的是,我应该查询什么以及如何获得完全相同的文档 ID。

For more understanding, take a chat app for instance.为了进一步了解,以聊天应用程序为例。 When a list tile showing another users profile pic and name is clicked, how can i ensure the next page that's meant to show more fields about that user, queries its data from the same document as the list tile perviously clicked.当单击显示另一个用户个人资料图片和名称的列表磁贴时,我如何确保旨在显示有关该用户的更多字段的下一页从与先前单击的列表磁贴相同的文档中查询其数据。

I'm not sure i explained that well but thanks anyway, would appreciate some help.我不确定我是否解释得很好,但无论如何,谢谢,希望能得到一些帮助。

Part of my ListView.builder, for more context我的 ListView.builder 的一部分,以获得更多上下文

FutureBuilder(
        future: getFifaTourneyData(),
        builder: (_, snapshot) {
          return ListView.builder(
              itemCount: snapshot.data.length,
              itemBuilder: (_, index) {
                return GestureDetector(
                    child: Container(
                      margin: EdgeInsets.only(top: 5),
                      width: 120,
                      height: 195,
                      decoration: BoxDecoration(
                        color: Colors.black,
                        borderRadius: BorderRadius.circular(4),
                        image: DecorationImage(
                            image:
                                AssetImage("assets/images/FifaImage3.jpg"),
                            colorFilter: new ColorFilter.mode(
                                Colors.black.withOpacity(0.5),
                                BlendMode.dstATop),
                            fit: BoxFit.cover),
                      ),
                      child: Container(
                        margin:
                            EdgeInsets.only(right: 10, left: 10, bottom: 0),
                        height: 190,
                        width: 340,
                        padding: EdgeInsets.all(10),
                        child: Column(children: <Widget>[
                          Container(
                            child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                children: <Widget>[
                                  Icon(
                                    FontAwesomeIcons.playstation,
                                    color: Colors.white,
                                    size: 35,
                                  ),
                                  Padding(
                                    padding:
                                        EdgeInsets.fromLTRB(130, 0, 0, 0),
                                  ),
                                  Text(
                                    "12 / 16 registered",
                                    style: TextStyle(
                                        color: Colors.white, fontSize: 13),
                                  )
                                ]),
                          ),
                          Padding(padding: EdgeInsets.only(top: 20)),
                          Container(
                            alignment: Alignment.center,
                            child: Text(
                                snapshot.data[index].data['tourneyname'] !=
                                        null
                                    ? snapshot
                                        .data[index].data['tourneyname']
                                    : 'No Name',
                                style: TextStyle(
                                    color: Colors.white,
                                    fontSize: 23,
                                    fontWeight: FontWeight.bold)),
                          ),
                          Padding(padding: EdgeInsets.only(top: 7)),
                                     .........
                      

If it's only the document id you need on the next page, you can pass it to it's constructor like so:如果它只是下一页您需要的文档 ID,您可以将它传递给它的构造函数,如下所示:

GestureDetector(
  onTap: () {
    Navigator.of(context).push(
      MaterialPageRoute(builder: (_) => NextPage(snapshot.data.documents[index].documentID)
    );
  },
  child: Container........
),

Your next page widget's constructor will be like:您的下一页小部件的构造函数将如下所示:

class NextPage extends StatelessWidget {
   final String docID;

   NextPage(this.docID);

   @override
    Widget build(BuildContext context) {
         return ........
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM