vedartm / paginate_firestore

A flutter package to simplify pagination with firestore data 🗃
https://pub.dev/packages/paginate_firestore
MIT License
113 stars 136 forks source link

force reloading items without refreshing. #116

Closed WouterVandenputte closed 2 years ago

WouterVandenputte commented 2 years ago

In my specific use-case scenario, the query given is given along user settings.

return PaginateFirestore(
                      itemBuilder: (context, documentSnapshots, index) => _buildPagingList(context, documentSnapshots, index),
                      query: _firestoreService.getDocs(settings: SettingsHelper.userSettings, orderBy: orderBy, descending: descending, limit: 10),
                      listeners: [
                        refreshChangeListener,
                      ],
                      itemBuilderType: PaginateBuilderType.listView,
                    );

but this setting can be changed overtime. I already have a subscription in my widget where I can catch the moment that this setting has changed. In there, I try to trigger the listener of the PaginateFireStore.

  void _onUserSettingsChanged(UserSettingsChangedEventArgs? args) {
    if (args != null) {
      setState(() {
        refreshChangeListener.refreshed = true;
      });
    }
  }

A breakpoint in the _firestoreService.getDocs method tells me that this does trigger a new call to the firestore database. But a breakpoint in the _buildPagingList method tells me that no items are repainted. So is there a way to force reloading the data and rebuilding all items?

vedartm commented 2 years ago

If you want the reload everything you can simply change the key of the PaginateFirestore when the setting changes. Please check this link to get the context.

Thanks for using the package. Feel free to reopen this if you are still facing this issue.