Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase Firestore事务致命异常_Firebase_Flutter_Dart_Google Cloud Firestore_Transactions - Fatal编程技术网

Firebase Firestore事务致命异常

Firebase Firestore事务致命异常,firebase,flutter,dart,google-cloud-firestore,transactions,Firebase,Flutter,Dart,Google Cloud Firestore,Transactions,嗨,伙计们,我的颤振应用程序有问题。 我使用firebase事务来管理数据,我使用的版本是cloud_firestore:0.13.5 我的应用程序实例在执行事务时崩溃。我研究了这个问题,但我找不到导致它的原因,代码过去工作时没有任何问题。 这是我的追踪 E/AndroidRuntime( 7246): FATAL EXCEPTION: AsyncTask #5 E/AndroidRuntime( 7246): Process: be.dezijwegel.blackbox, PID: 724

嗨,伙计们,我的颤振应用程序有问题。 我使用firebase事务来管理数据,我使用的版本是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$3.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$1.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$5.doInBackground(CloudFirestorePlugin.java:613)
E/AndroidRuntime( 7246):        at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin$5.doInBackground(CloudFirestorePlugin.java:608)
E/AndroidRuntime( 7246):        at android.os.AsyncTask$2.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事务的代码,我在其中看不到任何ussues

    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;
  }
static FuturegetAppInfo()异步
{
Appinfo-Appinfo;
DocumentReference docRef=
Firestore.instance.collection(“appinfo”).文档(“appinfo”);
等待Firestore.instance.runTransaction((事务)异步{
///获取应用程序信息文档
DocumentSnapshot snap=wait transaction.get(docRef);
if(snap.exists)
{
if(snap.data['current_version']!=null和&snap.data['current_version']!=“”)
{
字符串msg=“”;
if(snap.data['login\u message']!=null&&snap.data['login\u message']!=“”)
{
msg=snap.data['login_message'];
}
appinfo=新的appinfo(snap.data['current_version'],msg);
}
}
});
返回appinfo;
}

尝试在
wait Firestore.instance.runTransaction((事务事务事务)async{

DocumentReference docRef=Firestore.instance.collection(“appinfo”).document(“appinfo”);
将此作为事务的最后一行

//防止firestore事务错误
transaction.update(docRef,{})
返回承诺。解析(true)

尝试在
wait Firestore.instance.runTransaction((事务事务事务)async{

DocumentReference docRef=Firestore.instance.collection(“appinfo”).document(“appinfo”);
将此作为事务的最后一行

//防止firestore事务错误
transaction.update(docRef,{})
返回承诺。解析(true)

这会导致以下异常:
PlatformException(执行事务时出错,事务中读取的每个文档也必须写入,null)
您需要更新事务并返回Promise.Resolved。因此,如果我理解正确,每当我执行读取操作时,我都必须同时更新实例?因此每次读取时都会导致写入操作?不完全正确。在事务中,当您打开它时,必须关闭它,以便您不执行此操作。这会导致以下异常:
PlatformException(执行事务时出错,事务中读取的每个文档也必须写入,null)
您需要更新事务并返回Promise.Resolved。因此,如果我理解正确,每当我进行读取时,我必须同时更新实例?因此每次读取时都会导致写入操作?不完全是这样。在事务中,当您打开它时,您必须关闭它,因此您没有这样做。您为什么要使用事务来获取副本文档?仅读取文档时不存在争用风险。为什么要使用事务获取文档?仅读取文档时不存在争用风险。