Viswajith Menon
Viswajith Menon

Reputation: 11

In the ItemScreen the items are not displaying even though there are items inside the the firebase database '

` `class ItemsScreen extends StatefulWidget
   {
//
//final Sellers? model;
    final Products? model;
    ItemsScreen({this.model});


    @override
    _ItemsScreenState createState() => _ItemsScreenState();
  }

class _ItemsScreenState extends State<ItemsScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppBar(sellerUID: widget.model!.sellerUID),
      body: CustomScrollView(
        slivers: [
          SliverPersistentHeader(pinned: true, delegate: TextWidgetHeader(title: "Items of " + widget.model!.productTitle.toString())),
          StreamBuilder<QuerySnapshot>(
            stream: FirebaseFirestore.instance
                .collection("sellers")
                .doc(widget.model!.sellerUID)
                .collection("products")
                .doc(widget.model!.productID)
                .collection("items")
                .orderBy("publishedDate", descending: true)
                .snapshots(),
            builder: (context, snapshot)
            {
              return !snapshot.hasData
                  ? SliverToBoxAdapter(
                child: Center(child: circularProgress(),),
              )
                  : SliverStaggeredGrid.countBuilder(
                crossAxisCount: 1,
                staggeredTileBuilder: (c) => StaggeredTile.fit(1),
                itemBuilder: (context, index)
                {
                  Items model = Items.fromJson(
                    snapshot.data!.docs[index].data()! as Map<String, dynamic>,
                  );
                  return ItemsDesignWidget(
                    model: model,
                    context: context,
                  );
                },
                itemCount: snapshot.data!.docs.length,
              );
            },
          ),
        ],
      ),
    );
  }
}`

Item screen not displaying even though item inside firebase database Rechecked if the query is wrong checked the products screen it is working without any error when I try to retrieve just the item collection it displayes

StreamBuilder( stream: FirebaseFirestore.instance // .collection("sellers") // .doc(widget.model!.sellerUID) // .collection("products") // .doc(widget.model!.productID) .collection("items") .orderBy("publishedDate", descending: true) .snapshots(), builder: (context, snapshot)

Their is collection inside products called items this is what I cant retrive.

StreamBuilder( stream: FirebaseFirestore.instance .collection("sellers") .doc(widget.model!.sellerUID) .collection("products") .doc(widget.model!.productID) .collection("items") .orderBy("publishedDate", descending: true) .snapshots(), builder: (context, snapshot)"

Upvotes: 1

Views: 55

Answers (1)

Anas Mohamed
Anas Mohamed

Reputation: 64

i think you need to enable index for your query please check console of your project you might see firebase error message followed by link to firebase console take you to this page waiting to enable index for the query you entered

enter image description here

Upvotes: 0

Related Questions