小编Nac*_*izi的帖子

如何在颤振中捕获 StreamProvider 中的错误

当我尝试在 firestore 中获取不存在的数据时,我遇到了 StreamProvider 的问题。

Stream<CollectedItem> streamCollectedItem(String id,int category)
{
      return _db
          .collection('users')
          .document(id)
          .collection('CollectedItems').where('category', isEqualTo: category)
          .limit(1)
          .snapshots()
          .map((snap) => CollectedItem.fromFirestore(snap.documents.first));

    }
Run Code Online (Sandbox Code Playgroud)

我像这样调用这个函数:

return StreamProvider<CollectedItem>.value(
     value: db.streamCollectedItem(userID,collectMeNotification.category),
          child: AlertDialog(
            title: Text('Quantité'),
            content: SingleChildScrollView(
              child: popUp(collectMeNotification,userID)

              ),
Run Code Online (Sandbox Code Playgroud)

但是我遇到了“没有提供 catchError”的问题,因为我正在将我的流与不存在的数据链接起来。

我怎样才能解决这个问题 ?

dart flutter

3
推荐指数
1
解决办法
2591
查看次数

标签 统计

dart ×1

flutter ×1