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

Errors when using orderBy() #109

Closed p4-k4 closed 2 years ago

p4-k4 commented 2 years ago

When using the orderBy() method the following errors occur and get an infinite progress indicator on the UI.

#0      MethodChannelQuery.get (package:cloud_firestore_platform_interface/src/method_channel/method_channel_query.dart:110:7)
<asynchronous suspension>
#1      _JsonQuery.get (package:cloud_firestore/src/query.dart:390:9)
<asynchronous suspension>
#2      PaginationCubit.refreshPaginatedList (package:paginate_firestore/bloc/pagination_cubit.dart:61:29)
<asynchronous suspension>

However, after removing the orderBy() method, everything works fine. I've created index's for the collection and can confirm the respective fields exist.

This is how I'm implementing it:

class PostFeed extends StatelessWidget {
  const PostFeed(
      {required this.documentSnapshot, required this.header, Key? key})
      : super(key: key);
  final Query<Object?> documentSnapshot;
  final Widget header;

  @override
  Widget build(BuildContext context) {
    PaginateRefreshedChangeListener refreshChangeListener =
        PaginateRefreshedChangeListener();
    return RefreshIndicator(
      child: PaginateFirestore(
        header: SliverToBoxAdapter(
            child: Column(children: [header, const SizedBox(height: 150)])),
        // isLive: true,
        shrinkWrap: true,
        itemsPerPage: 3,
        query: documentSnapshot.orderBy('title'),
        listeners: [refreshChangeListener],
        itemBuilderType: PaginateBuilderType.listView,
        physics: const AlwaysScrollableScrollPhysics(),
        itemBuilder: (context, documentSnapshots, index) {
          final data = documentSnapshots[index];
          return Card(
              child: SizedBox(height: 300.9, child: Text(data.get('title'))));
        },
      ),
      onRefresh: () async => refreshChangeListener.refreshed = false,
    );
  }
}

Loving this package, it literally saved my ass, but this was a bit of a bummer. Any ideas?

Thanks

p4-k4 commented 2 years ago

Apologies, operator fault here. This can be totally ignored but for those wondering - This is what happens when you stack the orderBy() mehtod therefore, just use one.