【问题标题】:Deal with huge amount of data in Firestore in flutter project在flutter项目中处理Firestore中的海量数据
【发布时间】:2020-08-22 19:48:10
【问题描述】:

通常,我们在 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 项目中通常使用什么样的实用解决方案来处理这种情况?

P.S.:分页绝对是我可能的选择之一。但是有一些问题,因为我将对数据应用一些过滤器。例如,每次更改过滤条件时,我都必须查询 Firestore,这将导致数据使用量增加。而且似乎我只能使用getDocuments() 而不是snapshot 来获取流数据。

【问题讨论】:

  • 实现分页。

标签: firebase flutter google-cloud-firestore


【解决方案1】:

我认为使用分页更适合您。使用 Firebase Cloud Firestore 数据库在 Flutter 中实现分页可以提高您的应用性能并减少带宽使用(这是您最关心的问题之一)。关于this,有一些articles

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-26
    • 2021-05-05
    • 2020-08-24
    • 1970-01-01
    相关资源
    最近更新 更多