Amplify DataStore: How to know when sync is finished?

Viewed 320

How can we know that DataStore has finished the sync?

When doing the first await DataStore.query(MyEntity) after the user logged in, DataStore is returning right away and not waiting for the data to be synced with the cloud.

I want to wait for the sync to be completed and put a loading when the data isn't synced yet.

1 Answers

make your model class observable so that it can check for data in realtime

   Amplify.DataStore.observeQuery(MyEntity.classType).listen((event) {
  if (event.isSynced) {//boolean value
    print("Synced Successfully!");
    // even you can get synced data here also
      List< MyEntity> items = event.items;
  } else {
    //Show ProgressBar Here
    print("Fetching Data From Cloud");
  }
});
Related