Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To display Firestore's specific document in specific indexes, you can use the StreamBuilder widget to get a stream of data for the specific document and then use the ListView.builder widget to display the data in specific indexes.

Here's an example code:

import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class SpecificDocument extends StatelessWidget {
  final String documentId; // pass the document ID as a parameter

  SpecificDocument({this.documentId});

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
      stream: FirebaseFirestore.instance
          .collection('collection_name')
          .doc(documentId) // get document with specific ID
          .snapshots(),
      builder: (context, snapshot) {
        if (!snapshot.hasData) {
          return Center(
            child: CircularProgressIndicator(),
          );
        }
        var documentData = snapshot.data;
        return ListView.builder(
          itemCount: documentData.length,
          itemBuilder: (context, index) {
            return ListTile(
              title: Text(documentData['title']),
              subtitle: Text(documentData['subtitle']),
            );
          },
        );
      },
    );
  }
}

In this code, we pass the document ID as a parameter to the SpecificDocument widget. Then, we use the StreamBuilder widget to get a stream of data for the specific document using the doc method, which returns a DocumentReference.

Next, we check if the data is available using the hasData property of the snapshot. If data is available, we get the document data using the data property of the snapshot.

Finally, we use the ListView.builder widget to display the document data in specific indexes, by looping through the document data using the itemBuilder property. Here, we use the ListTile widget to display the title and subtitle of the document.