Federico Navarrete
Federico Navarrete

Reputation: 3274

Why this Firebase Listener is not being called?

Fellow programmers, I'm developing a new app with Firebase and Flutter and I have finished in an issue when I'm retrieving some data from my realtime database that looks like this:

example

My main issue is that this part of the code is not called at all: .listen((Event event) {//...}).

This is the part of the code that I'm using to retrieve the data:

static Future<StreamSubscription<Event>> getTodoStream(String todoKey,
      void onData(Todo todo)) async {
    String accountKey = await Preferences.getAccountKey();

    StreamSubscription<Event> subscription = FirebaseDatabase.instance
        .reference()
        .child("")
        .child(account)
        .child("")
        .child(Key)
        .onValue
        .listen((Event event) {
      var todo = new Todo.fromJson(event.snapshot.key, event.snapshot.value);
      onData(todo);
    });
}

I followed this tutorial:

https://www.youtube.com/watch?v=Bper2K92bd8&feature=youtu.be

And this is the code that I used as example:

https://gist.github.com/branflake2267/ea80ce71179c41fdd8bbdb796ca889f4

However, as I said the listen is not being triggered at all. Does any of you know why it's not working? Thanks for your advice.

Upvotes: 0

Views: 469

Answers (2)

Federico Navarrete
Federico Navarrete

Reputation: 3274

The main issue was the configuration of the database because it wasn't set as read/write.

Upvotes: 0

Feu
Feu

Reputation: 5780

If your code is indeed having these blank strings in it (child("")), I don't think it will work!

First give a try specifying a constant path which you know exists, like:

FirebaseDatabase.instance.reference()
  .child("/appointment-764c0/Akashdeep")
  .onValue.listen((Event event) {

Change something within Akashdeep...

Maybe then you can change your code to something like...

  .child("/$accountKey/$otherParam")

Upvotes: 1

Related Questions