Code Monkey home page Code Monkey logo

paginate_firestore's Introduction

Pagination in Firestore

All Contributors

pub package style: effective dart License: MIT

Setup

Use the same setup used for cloud_firestore package (or follow this).

Usage

In your pubspec.yaml

dependencies:
  paginate_firestore: # latest version

Import it

import 'package:paginate_firestore/paginate_firestore.dart';

Implement it

      PaginateFirestore(
        //item builder type is compulsory.
        itemBuilder: (context, documentSnapshots, index) {
          final data = documentSnapshots[index].data() as Map?;
          return ListTile(
            leading: CircleAvatar(child: Icon(Icons.person)),
            title: data == null ? Text('Error in data') : Text(data['name']),
            subtitle: Text(documentSnapshots[index].id),
          );
        },
        // orderBy is compulsory to enable pagination
        query: FirebaseFirestore.instance.collection('users').orderBy('name'),
        //Change types accordingly
        itemBuilderType: PaginateBuilderType.listView,
        // to fetch real-time data
        isLive: true,
      ),

To use with listeners:

      PaginateRefreshedChangeListener refreshChangeListener = PaginateRefreshedChangeListener();

      RefreshIndicator(
        child: PaginateFirestore(
          itemBuilder: (context, documentSnapshots, index) => ListTile(
            leading: CircleAvatar(child: Icon(Icons.person)),
            title: Text(documentSnapshots[index].data()['name']),
            subtitle: Text(documentSnapshots[index].id),
          ),
          // orderBy is compulsary to enable pagination
          query: Firestore.instance.collection('users').orderBy('name'),
          listeners: [
            refreshChangeListener,
          ],
        ),
        onRefresh: () async {
          refreshChangeListener.refreshed = true;
        },
      )

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue. If you fixed a bug or implemented a feature, please send a pull request.

Getting Started

This project is a starting point for a Dart package, a library module containing code that can be shared easily across multiple Flutter or Dart projects.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Contributors ✨

Thanks goes to these wonderful people:


Adam Dupuis

πŸ’»

Gautham

πŸ’»

Hafeez Ahmed

πŸ’»

Claudemir Casa

πŸ’»

Nikhil27bYt

πŸ“–

Ferri Sutanto

πŸ’»

jslattery26

πŸ’»

garrettApproachableGeek

πŸ’»

Sua MΓΊsica

πŸ’»

Austin Nelson

πŸ’»

This project follows the all-contributors specification. Contributions of any kind welcome!

paginate_firestore's People

Contributors

adamdupuis avatar allcontributors[bot] avatar atrope avatar austinn avatar claudemircasa avatar fer-ri avatar garrettapproachablegeek avatar imhafeez avatar kzlakowski avatar mafreud avatar nikhil27b avatar vedartm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

paginate_firestore's Issues

StreamSubscription needs to be closed

Hi

Thanks for your package. It saves a lot of my time πŸ‘

Btw, I noticed that when using isLive option as true, the stream is always active even we moved into another screen.

We need to capture the StreamSubscription from this line https://github.com/excogitatr/paginate_firestore/blob/master/lib/bloc/pagination_cubit.dart#L86 and cancel() on dispose.

Something like this

List<StreamSubscription<QuerySnapshot>>() streams = List<StreamSubscription<QuerySnapshot>>();

...

_getLiveDocuments() {
    ...
      StreamSubscription listener = localQuery.snapshots().listen((querySnapshot) {
        _emitPaginatedState(
          querySnapshot.docs,
          previousList:
              loadedState.documentSnapshots as List<QueryDocumentSnapshot>,
        );
      });
    }

  streams.add(listeners);
  }

...

streams.forEach((listener) => listener.cancel());

Thanks

cache query

Hi,
any plan to support cache query ? as you know we cannot imagine usage of firestore without caching for most of use case, just close and open the app will trigger new docs read if no local cache configured

Work with Sliver(NestedScrollView) scroll with SliverAppBar not working

hello ..
I love your packages but my project need to tab .
when I use this package on NestedScrollView but scroll with SliverAppBar not working .
if I fixed that by SliverChildListDelegate or any widget has scroll I have another problem with paginate firestore it's get all document in once .
how I fixed that ?
thank u ...

last index

I'd like to add a widget at the very bottom of the list (that scrolls with the list). However, in order to do this, I need to know the total number of items on the list. How can I do this ? Thanks.

How to update the Firestore query manually after a button press?

I have used this package for displaying the contents of my firestore collection. But I also have implemented filters such as the where clause is changed on the basis of the filter the user has chosen. I tried the store my query in a variable and change it but even after changing the query variable, I am not able to bring the filtered data. Is there any way that I can rebuild the whole PaginatedFirestore widget or any other approach that would help? Thanks.

Some features

It would be good if could animate data that fetches in real-time.

package status

Hi
I would like to have a status about this package, so @excogitatr @adamdupuis @claudemircasa @imhafeez @GauthamAsir all others contributors if it's possible to have answer of those questions :

  • do you have stop working on this package ? if yes please inform
  • any news about Support of streaming ?
  • do you plan to add cache query support ?
  • package is not up to date with last firestore version, so we cannot upgrade firebase due to this, so any plan to do this ?
  • what about open bugs ? there is no answer since 23 days for new open bugs

Thank you for your understanding

How to cast Document snapshot to my Model.

Thank you for this amazing library. Just wanna know what is the proper method to cast documentSnapshot to my Model i.e Product.
tried this inside item itemBuilder, but doesn't work.
Product products =documentSnapshot.data() as Product;

Error is _InternalLinkedHashMap<String, dynamic>' is not a subtype of type documentSnapshot.data.
Update: Ok, seems am doing it wrong. Can anyone help me mapping the snapshot data to an object

How to change the default no documents found message

Please I need to change the default no document found message when there are no documents found. I have used:

`if(snapshot.data().isEmpty || snapshot.data().length < 1 || !snapshot.data().isNotEmpty){

return Container(
margin: EdgeInsets.only(top: 170),
child: NoDataAvailable(
message: 'No Video posts Yet',
),
);
}`

but i still get the no document found message

search function

Hello, How do I use the search function?

I try with filterTerm but it returns a search and when I try to search for something else it is no longer possible, because the list was limited to the previous search.

The only solution I have found is refreshed all the time, but I don't think it is optimal

Listener example is not working

Listener example is not working
I am receiving syntax errors in Android Studio and will it be able to update whenever a collection changes with pulling a loader

Search listeners on 0.2.0

Hello,

from changelog of 0.2.0 version

Added support for Search and Refresh listeners

but when I'm looking on the implementation we throw UnimplementedError

  @override
  void initState() {
    _scrollController = widget.scrollController ?? ScrollController();
    if (widget.listeners != null) {
      for (var listener in widget.listeners) {
        if (listener is PaginateRefreshedChangeListener) {
          listener.addListener(() {
            if (listener.refreshed) {
              refresh();
            }
          });
        } else if (listener is PaginateSearchChangeListener) {
          listener.addListener(() {
            throw UnimplementedError();
          });
        }
      }
    }

so should we implement SearchChangeListener ? if yes can you please provide sample

Thanks

auto scrolling function

Thank you for contributing your excellent package.
Would it be possible to scroll automatically according to the given timer setting value?
Except basic ui, I want to use this package for upper screen on youtube screen and lower paginated firestore text data.
Thanks!

Adding a new document

Hello,

I'm implementing a simple chat using firestore, and I need a pagination. and this library sounds amazing, it handles loaders, pagination, search, all the stuff. Thanks!

However, I want to add a new document to the collection. the new document is not appended to the list view but it's added in the collection in firestore. and it works if I refresh the listview.

Is there any good way to add elements without refreshing the list?

Filtered result .

Hi,

Firestore document has a field called 'category' , i need to filter only those category field results ex: 'category' == 'men' or category == 'women'. So how do i filter documents based on these inputs . Can u give example code ?

Refresh on emptyDisplay

Right now you can't refresh when emptyDisplay is shown. This is because emptyDisplay isn't a child of a Scrollable.

I have solved it like this but it would be nice if this was the default behaviour.

    RefreshIndicator(
      child: PaginateFirestore(
        ...
        emptyDisplay: LayoutBuilder(
          builder: (ctx, constraints) => SingleChildScrollView(
            physics: AlwaysScrollableScrollPhysics(),
            child: Container(
              height: constraints.maxHeight,
              child: EmptyDisplay(),
            ),
          ),
        ),
      ),
    );

Thanks for a great package!

documentation of pub.dev has not been updated

Thanks for the latest update! Support of stream is big help for me :)
By the way, I found a minor documentation bug on pub.dev.
I'd be happy to check it out!

Github(latest)

 PaginateFirestore(
        itemBuilderType: PaginateBuilderType.listView, // listview and gridview
        itemBuilder: (index, context, documentSnapshot) => ListTile(
          leading: CircleAvatar(child: Icon(Icons.person)),
          title: Text(documentSnapshot.data()['name']),
          subtitle: Text(documentSnapshot.documentID),
        ),
        // orderBy is compulsary to enable pagination
        query: Firestore.instance.collection('users').orderBy('name'),
        isLive: true // to fetch real-time data
      )

pub.dev

 PaginateFirestore(
        itemBuilder: (context, documentSnapshot) => ListTile(
          leading: CircleAvatar(child: Icon(Icons.person)),
          title: Text(documentSnapshot.data['name']),
          subtitle: Text(documentSnapshot.documentID),
        ),
        // orderBy is compulsary to enable pagination
        query: Firestore.instance.collection('users').orderBy('name'),
        isLive: true // to fetch real-time data
      )

ListView is not scrollable

I am using the widget PaginateFirestore. It fetches data but the list is not scrolling. here is code.

 @override
  Widget build(BuildContext context) {
    return BlocProvider<TalentFavCubit>(
      create: (context) => TalentFavCubit(),
      child: SafeArea(
        child: Scaffold(
          body: Padding(
            padding: const EdgeInsets.all(20.0),
            child: SingleChildScrollView(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  Text('Talent Screen 1 home search'),
                  // _retrieveAllDocs,
                  _retrieveData,
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

  Widget get _retrieveData => PaginateFirestore(
    scrollDirection: Axis.vertical,
        physics: AlwaysScrollableScrollPhysics(),
        shrinkWrap: true,
        itemBuilderType: PaginateBuilderType.listView,
        query: FirebaseRepo.instance.fetchWorkerFormFieldsData(),
        itemBuilder: (index, context, documentSnapshot) {
          var data = documentSnapshot.data();
          return theUserInfo(data);
        },
        isLive: true,
      );

  Widget theUserInfo(var data) {
    TalentHireFavModel userData =
                   TalentHireFavModel.fromMap(data);
    return Card(
      child: Column(
        children: <Widget>[
          Text(userData.categories),
          SizedBox(height: 100.0,),
          Text(userData.skills),
          Text(userData.phoneNo),
          Text(userData.hourlyRate),
          Text(userData.professionalOverview),
          Text(userData.skills),
          Text(userData.expert),
          //_iconButton(userData.uid),
        ],
      ),
    );
  }
  
```}

Using in ListView

Is it possible to use this widget inside a ListView? It seems that all elements are loaded when I put it in a ListView.

Always show header

Is it possible to show the header widget even when no documents are found in the query?

Index

Would be awesome to have an index in the itemBuilder function!

Update Bloc Library

Because every version of paginate_firestore depends on flutter_bloc ^4.0.0 and project depends on flutter_bloc ^5.0.1, paginate_firestore is forbidden.

So, because project depends on paginate_firestore ^0.1.1, version solving failed.
pub get failed (1; So, because project depends on paginate_firestore ^0.1.1, version solving failed.)

Rebuild with a new querry

Hello,

I am trying to implement a search bar, and I need to change the query for every new search.
Problem: The list does not refresh itself when I am changing the query using a setState.

Is it supposed to work that way? Do you recommend another solution ?

Thank you for your help,
Benjamin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.