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

Updating the query of the paginated list #83

Closed Aurangseb closed 2 years ago

Aurangseb commented 3 years ago

Hi,

a really useful feature would be the ability to modify the query, e.g. when the user picks a different sort or where condition.

Right now the paginator sticks to the original query even if you update the query and setState() or use the PaginateRefreshedChangeListener, which makes it impossible to use in more complex scenarios.

marc-walton commented 3 years ago

Hi,

a really useful feature would be the ability to modify the query, e.g. when the user picks a different sort or where condition.

Right now the paginator sticks to the original query even if you update the query and setState() or use the PaginateRefreshedChangeListener, which makes it impossible to use in more complex scenarios.

You can use a key . Something like this

PaginateFirestore(
      key:ValueKey<String>(priceQuery),// priceQuery changes from user interaction
irshaadMax commented 3 years ago

@marc-walton thanks for the code. It works. But issue is it will refresh the whole PaginateFirestore widget along with it's header and footer. Not only the builder it self. Hope the project owner will fix this issue.

Omi231 commented 2 years ago

Hi, a really useful feature would be the ability to modify the query, e.g. when the user picks a different sort or where condition. Right now the paginator sticks to the original query even if you update the query and setState() or use the PaginateRefreshedChangeListener, which makes it impossible to use in more complex scenarios.

You can use a key . Something like this

PaginateFirestore(
      key:ValueKey<String>(priceQuery),// priceQuery changes from user interaction

hello, i am a novice developer. Can u explain it a bit more?

marc-walton commented 2 years ago

Hi, a really useful feature would be the ability to modify the query, e.g. when the user picks a different sort or where condition. Right now the paginator sticks to the original query even if you update the query and setState() or use the PaginateRefreshedChangeListener, which makes it impossible to use in more complex scenarios.

You can use a key . Something like this

PaginateFirestore(
      key:ValueKey<String>(priceQuery),// priceQuery changes from user interaction

hello, i am a novice developer. Can u explain it a bit more?

What didn't you understand?

Omi231 commented 2 years ago

@marc-walton It is giving me error:

// defining query
Query q = FirebaseFirestore.instance .collection('subcategories').where('category', isEqualTo: widget.category['ID']).orderBy('ID'); 

changeQuery(){
   setState({
       q = Firebase.instance.collection('items')...; // changing query
  });
}

//in body
PaginateFirebase(
key:  ValueKey<String>(q), // **(q) giving error: The Object type Query<Object> can't be assigned to parameter type String**
query: q,
....
)

// calling changeQuery() somewhere in logic .

Can you tell me what I am doing wrong in this code and why is it giving me error?

Thank you for help :)

marc-walton commented 2 years ago

@marc-walton It is giving me error:

// defining query
Query q = FirebaseFirestore.instance .collection('subcategories').where('category', isEqualTo: widget.category['ID']).orderBy('ID'); 

changeQuery(){
   setState({
       q = Firebase.instance.collection('items')...; // changing query
  });
}

//in body
PaginateFirebase(
key:  ValueKey<String>(q), // **(q) giving error: 

Can you tell me what I am doing wrong in this code and why is it giving me error?
l
Thank you for help : clears s

@marc-walton It is giving me error:

// defining query Query q = FirebaseFirestore.instance .collection('subcategories').where('category', isEqualTo: widget.category['ID']).orderBy('ID');

changeQuery(){ setState({ q = Firebase.instance.collection('items')...; // changing query }); }

//in body PaginateFirebase( key: ValueKey(q), // (q) giving error: The Object type Query can't be assigned to parameter type String query: q, .... )

// calling changeQuery() somewhere in logic .



Can you tell me what I am doing wrong in this code and why is it giving me error?

Thank you for help :)

The error clearly states you can't pass Query , it requires a string. ValueKey👈. So declare a string value say String valueForTheKey = "firstQuery".

Then pass it in the valueKey(value). So whenever the String value is changed , the builders builds again. The query:q, change it to something like this with if else


Hope I could help you
Omi231 commented 2 years ago

@marc-walton thank you so much for ur time and help for teaching me a new thing :) u are awesome!

vedartm commented 2 years ago

Hope this issue is resolved. Thanks for using the package 🎉. Feel free to reopen if you face this issue.