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

Limit total items to be loaded #147

Open ghost opened 2 years ago

ghost commented 2 years ago

First of all this package is very handy and I use it in several projects, so I appreciate it.

My intention is to load 5 new documents each time user swipes the first 5 documents, so I have this attribute on my widget itemsPerPage: 5,. But my main goal is to restrict some users the maximum amount of documents they can load. Like in a query you would normally use in a FutureBuilder;

child: FutureBuilder<QuerySnapshot>(
          future: FirebaseFirestore.instance
              .collection('Upcoming')
              .orderBy('ReleaseTimestamp')
              .where('ReleaseTimestamp', isGreaterThan: Timestamp.now())
              .limit(3) // This actually only loads 3 documents totally
              .get(),

But when trying to do the exact same procedure with this package the limit method used in the query is ignored;

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

  @override
  Widget build(BuildContext context) {
    return PaginateFirestore(
      pageController: PageController(viewportFraction: 0.85),
      scrollDirection: Axis.horizontal,
      itemsPerPage: 5,
      itemBuilderType: PaginateBuilderType.pageView,
      query: FirebaseFirestore.instance
          .collection('Menu')
          .orderBy('Timestamp', descending: true)
          .limit(10), // ! THIS DOESN'T WORK
      itemBuilder: (context, snapshot, index) {
        return Text(snapshot.toString());
      },
    );
  }
}

Any idea how can I limit the total queried documents while also using the pagination? Like I want some users to load max 100 documents but paginate these 100 documents 20 by 20.

RoyalCoder88 commented 1 year ago

@appleist-a bump for this idea, will be a great feature!