Flutter: Firestore transaction crashes only on phy

2020-07-26 07:09发布

问题:

I have a simple transaction that updates a Firestore document. It works correctly on Android devices, Android Emulators and iOS emulators, but crashes on a physical iOS device:

Firestore.instance.runTransaction((Transaction tx) async {
    DocumentSnapshot docSnapshot = await tx.get(docRef);

      tx.update(
        docRef,
        {
          'title':'A Title'
        },
      );
    }

Error:

-[NSError init] called; this results in an invalid NSError instance. It will raise an exception in a future release. Please call errorWithDomain:code:userInfo: or initWithDomain:code:userInfo:. This message shown only once.

Assertion failure in void firebase::firestore::core::Transaction::EnsureCommitNotCalled()(), /Users/path_to_app/ios/Pods/FirebaseFirestore/Firestore/core/src/firebase/firestore/core/transaction.mm:198 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'FIRESTORE INTERNAL ASSERTION FAILED: A transaction object cannot be used after its update callback has been invoked. (expected !committed_)'

I'm not sure what the error means, and my Google quest has hit a dead-end. Really hoping someone can point out what the problem might be!