0

I am using the paginate_firestore dependency to paginate my documents retrieved from Firestore with the following Query:

query: FirebaseFirestore.instance
          .collection('Menu')
          .orderBy('Timestamp', descending: true)
          .limit(10),

There are 15 documents in the Menu collection and no matter what .limit() I specify it will load all the 15 documents. I have tried deleting cache/storage & uninstalling the application.

Update 1: FULL CODE

class HomeUpcomingWidget extends StatelessWidget {
  const HomeUpcomingWidget({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(
        horizontal: Get.width * .1,
        vertical: 15,
      ),
      child: Hero(
        tag: 'MaterialContainerHero',
        child: Material(
          elevation: 10,
          borderRadius: BorderRadius.circular(15),
          child: PaginateFirestore(
            padding: const EdgeInsets.all(8),
            scrollDirection: Axis.horizontal,
            itemBuilderType: PaginateBuilderType.pageView,
            initialLoader: const Center(child: CupertinoActivityIndicator()),
            query: FirebaseFirestore.instance.collection('Upcoming').limit(2),
            itemBuilder: (context, snapshot, index) {
              var model = UpcomingModel.fromMap(snapshot[index].data() as Map);

              return Center(
                child: Text(
                    '${model.chartTitle}\n${model.chartSource}\n${model.chartImage}'),
              );
            },
          ),
        ),
      ),
    );
  }
}
SLendeR
  • 839
  • 7
  • 25
  • can you share Firebase Firestore Security rule with us? – Bilal Almefleh Aug 15 '22 at 07:38
  • may this help you > [Query with limit flutter firebase firestore](https://stackoverflow.com/questions/66492089/query-with-limit-flutter-firebase-firestore) – Bilal Almefleh Aug 15 '22 at 07:42
  • 1
    https://i.imgur.com/QYYapY8.png These are my Firestore Rules, I have checked that topic (which is not related at all since that user has problems using "where" & "orderBy" together. – SLendeR Aug 15 '22 at 07:54
  • if you use paginate_firestor dependency you dont need to limit ,its doing that by self see there example its contain this code to limit ____________ query: FirebaseFirestore.instance.collection('users').orderBy('name'), itemsPerPage: 5, // to fetch real-time data isLive: true, – Bilal Almefleh Aug 15 '22 at 08:45
  • https://pub.dev/packages/paginate_firestore/example – Bilal Almefleh Aug 15 '22 at 08:46
  • 1
    I do understand what are you trying to say but *itemsPerPage* decides the amount of documents to load after each page skip. If I am displaying 5 documents per page with the help of this parameter I want to **limit** the total **to be loaded** documents to 10 so this *itemsPerPage* function gets triggered twice. – SLendeR Aug 15 '22 at 10:08
  • can you refer to the [link](https://github.com/firebase/firebase-js-sdk/issues/849) and [thread](https://stackoverflow.com/a/61662691/15774176) is it helpful? – Divyani Yadav Aug 15 '22 at 12:20
  • No, separating query variables didn't help and the data is not cached on the devices I am trying on. – SLendeR Aug 16 '22 at 16:48
  • is this issue resolved now? – Divyani Yadav Aug 25 '22 at 08:34
  • No it is not resolved. – SLendeR Aug 25 '22 at 10:02
  • if issue persist, have a look this [thread](https://stackoverflow.com/a/59250190/15774176) , is it helpful? – Divyani Yadav Sep 06 '22 at 12:46

1 Answers1

0

Requested this feature from package dev but they seem to care too little so I have decided to switch to the in-built pagination on flutterfire_ui package developed by the Firebase team.

SLendeR
  • 839
  • 7
  • 25