firebase - 在flutter项目中处理Firestore中的海量数据
问题描述
通常,我们在 Flutter 项目中使用 StreamProvider 来处理来自 FireStore 的数据,如下所示:
// I have a collection of Customer in my DataService
Stream<List<Client>> streamCustomers() {
return Firestore.instance.collection('customers').snapshots().map((list) =>
list.documents.map((doc) => Customer.fromMap(doc.data, doc.documentID)).toList());
}
这是流数据的提供者:
Expanded(
child: StreamProvider<List<Customer>>.value(
value: _dataSvc.streamCustomers(),
child: CustomerListWidget(),
),
);
这是流数据消耗的地方:
final _customers = Provider.of<List<Customer>>(context);
return Container(
child: _customers == null? Text('Loading...') : _buildList(context, _customers),
);
我将在 中显示所有客户数据CustomerListWidget
。因为Customer
收集的数据非常大(超过10,000 - 50,000条记录)。显然这不是有效的解决方案。我想知道通常在 Flutter/Firestore 项目中使用什么样的实用解决方案来处理这种情况?
PS:分页绝对是我可能的选择之一。但是有一些问题,因为我将对数据应用一些过滤器。例如,每次更改过滤条件时我都必须查询 Firestore,这将导致数据使用量增加。而且似乎我只能使用getDocuments()
而不是snapshot
获取 Stream 数据。