Flutter show saved bookmark from Firestore

Viewed 51

I want to show a story from firebase firestore after that story is saved through a click from a bookmark icon.

IconButton(
                      icon: favIcon,
                      onPressed: () {
                        setState(
                          () async {
                            if (widget.story.favorite.contains(user.uid)) {
                              widget.story.favorite.remove(user.uid);
                            } else {
                              widget.story.favorite.add(user.uid);
                              await StoryService().updatestory(widget.story);
                              // await _storyReference
                              //     .doc(widget.story.id)
                              //     .update(widget.story.toMap());
                            }
                          },
                        );
                      },
                    ),

This is the method that I use to display the story.

 Column(
              children: story
                  .where((favorite) => story.contains(_user!.uid))
                  .map((StoryModel story) {
                return StoriesBookmark(story);
              }).toList(),
            ),

But that is not return anything nor display an error. Just white screen and no error at the codes.

Does anybody know how am I supposed to do? and is that a good way to retrieve data from the database?

1 Answers

Try using docs instead of doc

Column(
          children: snapshot.data.docs.map<Widget>(
                (e) => ItemCard(
                  e.data()['name'],
                  e.data()['author'],
                  e.data()['rating'],
                  e.data()['storytext'],
                  e.data()['imageUrl'],
          
                ),
              )
              .toList(),

I hope this works!

Related