Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – Stream returning null even though EVERY print statement is getting printed

Posted on November 11, 2022 By

Solution 1 :

Try:

var rooms = await FirebaseFirestore.instance
  .collection("rooms")
  .where("users", arrayContains: userId)
  .orderBy("latestMessageTime", descending: true)
  .snapshots();

Problem :

I have a Stream which seems to work perfectly fine: Every print statement you see in the stream is getting printed. Also when calling if(snapshot.hasData) it apparently is true. But still, my stream only returns the following: AsyncSnapshot<List<dynamic>>(ConnectionState.done, [], null, null).

What do I need to change in order to be able to access the Data in my retVal variable?

   Stream<List>? roomsListStream() {
    try {
      List<RoomsListModel> retVal = [];
      print("userId: $userId");
      var rooms = FirebaseFirestore.instance
          .collection("rooms")
          .where("users", arrayContains: userId)
          .orderBy("latestMessageTime", descending: true)
          .snapshots();
      print("rooms: $rooms");
      rooms.forEach((element) {
        element.docs.forEach((element) {
          print("element: $element");
          var room = element.data();
          print("room: $room");
          var roomId = room["roomId"];
          var otherUserId =
              room["users"].firstWhere((element) => element != userId);
          var lastMessage = room["latestMessage"];
          var lastMessageTime = room["latestMessageTime"];
          print("otherUserId: $otherUserId");
          getOtherUser(otherUserId).then((value) {
            print("value: $value");
            var avatar = value["photoUrl"];
            var name = value["name"];
            retVal.add(RoomsListModel(
                roomId: roomId,
                otherUserId: otherUserId,
                avatar: avatar,
                name: name,
                lastMessage: lastMessage,
                lastMessageTime: lastMessageTime));
          });
        });
      });
      return Stream.value(retVal);
    } catch (e) {
      print("Error: $e");
    }
  }

Comments

Comment posted by dart.dev/tutorials/language/streams#modify-stream-methods

see

Comment posted by cipano

Could you kindly elaborate on that? I don’t really get where and why I would need that?

Comment posted by pskink

why you would need that? add

Comment posted by pskink

check when that print is called, it is called

Comment posted by pskink

i already answered that: return

Comment posted by Tyler2P

Your answer could be improved by adding more information on what the code does and how it helps the OP.

READ  [FIXED] android - Firestore error retrieving data using Kotlin
Powered by Inline Related Posts
Android Tags:android, dart, flutter, google-cloud-firestore

Post navigation

Previous Post: Do you have to pay for MyNetDiary?
Next Post: [FIXED] Simple Cucumber Test is not running on Sample Android Project

Related Posts

[FIXED] windows – Android Studio won’t open after update Android
[FIXED] android – I cannot join volley 1.1.1 In Syria, it is prohibited, but I use the proxy. Is there a way to communicate? Android
[FIXED] java – How Appium Page factory will pick correct xpath when both Android & IOS Xpaths are defined Android
[FIXED] adb – How to verify if android.permission.WRITE_SECURE_SETTINGS been provided? Android
[FIXED] android – Is SVG image officialy support by flutter? Android
[FIXED] java – How to upload the public url for an image uploaded to the Firebase Cloud Storage to the Realtime Database Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What are the main features of Islamic education?
  • Is the Jeep 4xe worth it?
  • How does the ringer work on cast iron?
  • What is the biggest size interior door?
  • Is blue raspberry an original Jolly Rancher flavor?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme