Firestore 事务致命异常

Firestore transaction fatal exception

大家好,我的 flutter 应用程序有问题。 我使用firebase transaction来管理数据,我使用的版本是cloud_firestore: 0.13.5

我的应用程序实例在执行事务时崩溃。我调查了这个问题,但我找不到导致它的原因,代码过去没有任何问题。 这是我的堆栈跟踪。

E/AndroidRuntime( 7246): FATAL EXCEPTION: AsyncTask #5
E/AndroidRuntime( 7246): Process: be.dezijwegel.blackbox, 
PID: 7246
E/AndroidRuntime( 7246): java.lang.RuntimeException: An error 
occurred while executing doInBackground()
E/AndroidRuntime( 7246):        at 
android.os.AsyncTask.done(AsyncTask.java:354)
E/AndroidRuntime( 7246):        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime( 7246):        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime( 7246):        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime( 7246):        at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:245)
E/AndroidRuntime( 7246):        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime( 7246):        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime( 7246):        at java.lang.Thread.run(Thread.java:764)
E/AndroidRuntime( 7246): Caused by: java.lang.AssertionError: INTERNAL ASSERTION FAILED: A transaction object cannot be used after its update callback has been invoked.
E/AndroidRuntime( 7246):        at com.google.firebase.firestore.util.Assert.fail(com.google.firebase:firebase-firestore@@21.3.0:46)
E/AndroidRuntime( 7246):        at com.google.firebase.firestore.util.Assert.hardAssert(com.google.firebase:firebase-firestore@@21.3.0:31)
E/AndroidRuntime( 7246):        at com.google.firebase.firestore.core.Transaction.ensureCommitNotCalled(com.google.firebase:firebase-firestore@@21.3.0:246)
E/AndroidRuntime( 7246):        at com.google.firebase.firestore.core.Transaction.lookup(com.google.firebase:firebase-firestore@@21.3.0:81)
E/AndroidRuntime( 7246):        at com.google.firebase.firestore.Transaction.getAsync(com.google.firebase:firebase-firestore@@21.3.0:191)
E/AndroidRuntime( 7246):        at com.google.firebase.firestore.Transaction.get(com.google.firebase:firebase-firestore@@21.3.0:228)
E/AndroidRuntime( 7246):        at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.doInBackground(CloudFirestorePlugin.java:613)
E/AndroidRuntime( 7246):        at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin.doInBackground(CloudFirestorePlugin.java:608)
E/AndroidRuntime( 7246):        at android.os.AsyncTask.call(AsyncTask.java:333)
E/AndroidRuntime( 7246):        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime( 7246):        ... 4 more
D/OSTracker( 7246): OS Event: crash
I/Process ( 7246): Sending signal. PID: 7246 SIG: 9
Lost connection to device.

仅供参考,这是我们用来执行 get 事务的代码,我看不到其中的任何用法。

    static Future< Appinfo > getAppInfo() async
  {
    Appinfo appinfo;
    DocumentReference docRef = 
 Firestore.instance.collection("appinfo").document("appinfo");

    await Firestore.instance.runTransaction((Transaction transaction) async {
      /// Get the app info document
      DocumentSnapshot snap = await transaction.get(docRef);

      if (snap.exists)
      {
        if (snap.data['current_version'] != null && snap.data['current_version'] != "")
        {
          String msg = "";
          if (snap.data['login_message'] != null && snap.data['login_message'] != "")
          {
            msg = snap.data['login_message'];
          }

          appinfo = new Appinfo(snap.data['current_version'], msg);

        }


      }

    });
    return appinfo;
  }

尝试将以下行放在 await Firestore.instance.runTransaction((Transaction transaction) async {

上方
 DocumentReference docRef = Firestore.instance.collection("appinfo").document("appinfo");

将此作为交易的最后一行

//to prevent firestore transaction error
 transaction.update(docRef, {})
 return Promise.resolve(true)