简体   繁体   English

Flutter:卡在从 Firestore 获取集合

[英]Flutter: stuck getting collection from Firestore

DocumentReference ref = FirebaseFirestore.instance
        .collection('invoices')
        .doc(authService.getUser().uid); // or non existing ID

    // here works if I return {}

    final doc = await ref.get();
    final data = doc.data();

When trying locally either with simulator or with real device (connected by usb) works fine, but in released app, the await takes for ever.当使用模拟器或真实设备(通过 USB 连接)在本地尝试时工作正常,但在已发布的应用程序中,等待将永远存在。

This was also working ok before updating to flutter 2.8 but now it fails only on Android这在更新到 flutter 2.8 之前也可以正常工作,但现在它仅在 Android 上失败

I put everything inside a trycatch我把所有东西都放在一个trycatch里

try { DocumentReference ref = FirebaseFirestore.instance.collection('invoices').doc(authService.getUser().uid);尝试 { DocumentReference ref = FirebaseFirestore.instance.collection('invoices').doc(authService.getUser().uid);

      final doc = await ref.get();
      final data = doc.data();

      Map savedCompanyInfo = data != null ? data as Map<String, dynamic> : {};
      myRents.companyInfo = savedCompanyInfo;

      return savedCompanyInfo;
    } catch (e) {
      return {};
    }

Reposting my comments as they seemed to have helped:重新发布我的评论,因为他们似乎有帮助:

You should handle possible exceptions.您应该处理可能的异常。 The get method returns an instance of Future , which may complete with an error. get方法返回一个Future的实例,该实例可能会出现错误。 When awaiting it, it may throw.在等待它时,它可能会抛出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM