0

I followed all steps in documentation, but this function never gets called:

subscription.on(LiveQueryEvent.create,
        (value) {});

All I receive in terminal is this: "ReSubScription:{}".
I am trying to capture the event when one of my classes in the database gets a new record/entry. If requested, I can arrange a demo codebase, but please help me get through this.

PS: I am calling this subscription.on() method in initState() method of a stateful widget, not in main().

UPDATE
I am sharing link of git repo of a minimal app to demonstrate what I did. Here is the link

Please see what have I done incorrect with livequery. Would be grateful for any pointers/guidance.

UPDATE 2nd
Please note, I've hardcoded adminId (objectId of admin logged in). Check TODO plz.

My Testing procedure:

  1. Create a user from backend database manually using Parse Dashboard. Plz Keep username = email.
  2. Open app. Click admin button. Go to AdminLogin page and enter your email and password.
  3. If you are successful, app will navigate to next white screen. This confirms that auth was done successfully.
  4. Open the app again. Click user button. Go to UserForm.
  5. Enter name and hit subscriber button. This will create a new class in Database by the name "Subscribers" and add columns "adminId" and "name" (plz hardcode the adminId in code bcoz you already know it)
  6. Now open the app again and go to admin and login again to move to control panel (white screen).
  7. Wait for the back4app to send trigger/callback. (which shows ReSubScription:{}).
spkakkar
  • 113
  • 4
  • Davi Macêdo help me. I hope you get to see this question soon. :-) – spkakkar Jan 03 '21 at 20:47
  • 1
    Could you please share more of your code? H/ow you are initializing the SDK, the subscription var and how you are testing it? – Davi Macêdo Jan 04 '21 at 06:20
  • @DaviMacêdo, surely. Give me some hours. I am recreating a minimal demo app to reproduce this ReSubScription:{} thing. – spkakkar Jan 04 '21 at 11:03
  • Hi @DaviMacêdo, I've shared the link of project. Could you please have a look at it and tell me where/what I did wrong ? – spkakkar Jan 04 '21 at 15:35

1 Answers1

1

The problem is related to the code below:

    final ParseObject object = ParseObject('Subscribers');
    final response = await object.create();
    if (response.success && response.count > 0) {
      final ParseObject record = response.results[0];
      record.set('name', name);
      record.set('adminId', adminId);
      await record.save();
    }

Note that first you create the object with no adminId and that's why your event is not triggered. You then set the adminId and update the object. In that moment, your enter event should be triggered. Please listen to all different events (create, enter, update, leave, delete) and you will see it happening.

Davi Macêdo
  • 2,954
  • 1
  • 8
  • 11