我正在使用Flutter编写应用程序,我必须使用该Firestore.instance.runTransaction(Transaction tx)方法进行交易.在我的Transaction对象(或方法)中,我必须使用文档引用更新一些数据.
_firestore.runTransaction((Transaction x) async {
await x.update(Aref, {'data': itemA - y});
await x.update(Bref, {'data': itemB + y});
})
Run Code Online (Sandbox Code Playgroud)
代码运行时抛出异常(这里是控制台日志):
E/MethodChannel#plugins.flutter.io/cloud_firestore(32612):无法处理方法调用结果E/MethodChannel#plugins.flutter.io/cloud_firestore(32612):java.lang.IllegalStateException:任务已完成E/MethodChannel# plugins.flutter.io/cloud_firestore(32612):at com.google.android.gms.common.internal.Preconditions.checkState(Unknown来源:8)E/MethodChannel#plugins.flutter.io/cloud_firestore(32612):at com .google.android.gms.tasks.zzu.zzdr(未知来源:8)E/MethodChannel#plugins.flutter.io/cloud_firestore(32612):at com.google.android.gms.tasks.zzu.setResult(Unknown Source :3)E/MethodChannel#plugins.flutter.io/cloud_firestore(32612):at com.google.android.gms.tasks.TaskCompletionSource.setResult(Unknown来源:2)E/MethodChannel#plugins.flutter.io/cloud_firestore( 32612):at io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin $ 3 $ 1.success(CloudFirestorePlugin.java:283)E/MethodChannel#plugins.flutter.io/cloud_firestore(32612):at io.flutter.plugin.common. MethodC hannel $ IncomingResultHandler.reply(MethodChannel.java:169)E/MethodChannel#plugins.flutter.io/cloud_firestore(32612):at io.flutter.view.FlutterNativeView.handlePlatformMessageResponse(FlutterNativeView.java:187)E/MethodChannel#plugins. flutter.io/cloud_firestore(32612):在android.os.MessageQueue.nativePollOnce(Native Method)E/MethodChannel#plugins.flutter.io/cloud_firestore(32612):at android.os.MessageQueue.next(MessageQueue.java:325 )E/MethodChannel#plugins.flutter.io/cloud_firestore(32612):at android.os.Looper.loop(Looper.java:142)