loadDataWithQuery<T extends BaseEntityDataModel> method
Loads data with a query from the specified path and returns it as a Future<List<T>>.
path - The path to the data.
builder - The function to build the data.
queryBuilder - The function to build the query.
sort - The function to sort the data.
Implementation
Future<List<T>> loadDataWithQuery<T extends BaseEntityDataModel>({
required String path,
required T Function(Map<String, dynamic>? jsondata, String docId) builder,
Query Function(Query query)? queryBuilder,
int Function(T lhs, T rhs)? sort,
}) {
Query query = _fireStore.collection(path);
if (queryBuilder != null) {
query = queryBuilder(query);
}
final snapshots = query.get();
return snapshots.then((snapshot) {
final result = snapshot.docs
.map(
(snapshot) => builder(
snapshot.data() as Map<String, dynamic>,
snapshot.id,
),
)
.toList();
if (sort != null) {
result.sort(sort);
}
return result;
});
}