1
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.

This was also working ok before updating to flutter 2.8 but now it fails only on Android

Dani
  • 3,128
  • 2
  • 43
  • 91
  • Do you handle possible exceptions? – Riwen Dec 18 '21 at 18:35
  • 2
    Your document is literally named "authService.getUser().uid", that exact string? – Doug Stevenson Dec 18 '21 at 18:35
  • @DougStevenson good catch, I was testing with wrong ids to check what I got instead, but not related to the error anyway – Dani Dec 18 '21 at 18:57
  • @Riwen I handle possible null Map savedCompanyInfo = data != null ? data as Map : {}; but what's the exception for that? It always return something, right? – Dani Dec 18 '21 at 18:58
  • `get` always returns an instance of `Future`, yes. However, futures may complete with an error, which you should *really* handle, in my opinion. – Riwen Dec 18 '21 at 19:12
  • @Riwen you were right. I put everything inside a trycatch and returned {} in case something was wrong. But I don't know why only in released app this error is happening (and know sure how to check what the error ir) – Dani Dec 18 '21 at 20:05
  • Had to open a different question for that since this was resolved: https://stackoverflow.com/questions/70406740/flutter-not-getting-collection-in-released-app – Dani Dec 18 '21 at 20:07
  • 2
    Should I repost my comment as an answer so that you can accept it? – Riwen Dec 18 '21 at 20:34

2 Answers2

1

I put everything inside a trycatch

try { 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 {};
    }
Dani
  • 3,128
  • 2
  • 43
  • 91
1

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. When awaiting it, it may throw.

Riwen
  • 4,734
  • 2
  • 19
  • 31