Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振-如何获取快照的索引值?_Flutter_Google Cloud Firestore_Document - Fatal编程技术网

Flutter 颤振-如何获取快照的索引值?

Flutter 颤振-如何获取快照的索引值?,flutter,google-cloud-firestore,document,Flutter,Google Cloud Firestore,Document,我想获取颤振列表视图中的所有文档。。所以我做这个 class AudioScreenList extends StatefulWidget { @override _AudioScreenListState createState() => _AudioScreenListState(); } class _AudioScreenListState extends State<AudioScreenList> { bool isPerformingRequest

我想获取颤振列表视图中的所有文档。。所以我做这个

class AudioScreenList extends StatefulWidget {
  @override
  _AudioScreenListState createState() => _AudioScreenListState();
}

class _AudioScreenListState extends State<AudioScreenList> {
  bool isPerformingRequest = false;

  static const String _collectionRussian = 'users';
  static const String _loadingTextRussian = 'Loading...';
  static const String _speechTitle = 'full_name';
  static const String _speechSubtitle = 'coins';
  static const String _audioLink = 'audioLink';
  static const String _pastorCode = 'pastorCode';
  static const String _pastorName = 'coins';
  static const String _id = "id";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: StreamBuilder(
        stream: FirebaseFirestore.instance
            .collection(_collectionRussian)
            // .orderBy(_id, descending: true)
            .snapshots(),
        builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
          if (!snapshot.hasData)
            return const Center(
                child: Text(
              _loadingTextRussian,
              style: TextStyle(fontSize: 25.0, color: Colors.grey),
            ));
          return ListView(children: getExpenseItems(snapshot));
        },
      ),
    );
  }

  getExpenseItems(AsyncSnapshot<QuerySnapshot> snapshot) {
    // ignore: deprecated_member_use
    return snapshot.data.documents
        .map(
          (doc) => Container(
            margin: const EdgeInsets.fromLTRB(0.0, 8.0, 0.0, 0.0),
            child: ListTile(
                leading: Container(
                  width: 70.0,
                  height: 70.0,
                  child: Image.asset(
                    "assets/profile.png",
                    fit: BoxFit.cover,
                  ),
                ),
                title: Text(doc[_speechTitle]),
                subtitle: Text(
                  doc[_speechSubtitle].toString(),
                ),
                onTap: () => {}),
          ),
        )
        .toList();
  }
}
class AudioScreenList扩展了StatefulWidget{
@凌驾
_AudioScreenListState createState()=>_AudioScreenListState();
}
类_AudioScreenListState扩展状态

我试过了,但没用

snapshot.data.doc['index']


我想在单击列表项时获取文档id。

您提出了两个不同的问题。您问题的标题是关于在
map()
函数中确定每个文档的索引,您可以在此处找到答案:

另一个问题是关于查找每个文档的ID,您可以在循环中使用
doc.ID
。例如:

return snapshot.data.documents
    .map(
      (doc) => Container(
        margin: const EdgeInsets.fromLTRB(0.0, 8.0, 0.0, 0.0),
        child: ListTile(
            ...,
            onTap: () => { print(doc.id) }),
      ),