Closed yelaseck closed 2 years ago
There are 2 ways
the first one is when you need to paginate your data so you can just use get and every thing works fine
@override
ListLoadingHandler<FakeItem>? get handler => DefaultListLoadingHandler(
loadData: (skip, pageSize, cancelToken) async {
var cursor;
if (skip > 0) {
cursor = state.asLoaded()?.items.last.id;
}
Future<QuerySnapshot<Map<String, dynamic>>> future;
if (cursor != null) {
future = FirebaseFirestore.instance
.collection('collection')
.startAfter(cursor)
.limit(pageSize)
.get();
} else {
future = FirebaseFirestore.instance
.collection('collection')
.limit(pageSize)
.get();
}
return future.then((value) {
return ReadyListResponse.success(items: [
/// ... resolve your item
], total: 10);
});
},
controller: this,
);
the second if you need to listen to data changes then no need for paging so you can just return null to handler and use the normal way
ListLoadingHandler<FakeItem>? get handler
var firebaseStream=...
firebaseStream.listen((data){
if(has data)
emit(ReadyListState.loaded(items: [],total: 0));
else
emit(ReadyListState.empty());
});
Thank It works!
Hi, How can I Fetch data from my firebase firestore?
ListLoadingHandler<FakeItem>? get handler => DefaultListLoadingHandler( loadData: (skip, pageSize, cancelToken) async { /// Fetch your data }, controller: this, );