当前位置: 首页 > 知识库问答 >
问题:

Flutter cloud_firestore在Android上的插件事务

湛宜春
2023-03-14

是否有人使用cloud_firestore插件成功地运行了事务?我得到以下错误:

E/AndroidRuntime(26208):致命异常:AsyncTask#2 E/AndroidRuntime(26208):process:io.flutter.plugins.googleSigninexample,PID:26208 E/AndroidRuntime(26208):java.lang.runtimeException:>执行doInBackground()E/AndroidRuntime(26208):at Android.os.AsyncTask$3时出错。Done(AsyncTask.java:353)E/AndroidRuntime(26208):at java.util.concurrent.futureTask.setException(FutureTask.java:252)E/AndroidRuntime(26208):at java.util.concurrent.futureTask.run(FutureTask.java:271)E/AndroidRuntime(26208):at android.os.AsyncTask$serialExecutor$1.run(AsyncTask.java:245)E/AndroidRuntime(26208):at android.os.AsyncTask:245):at tor$worker.run(threadpoolexecutor.java:636)e/AndroidRuntime(26208):at java.lang.thread.run(thread.java:764)e/AndroidRuntime(26208):cased by:java.lang.IllegalArgumentException:>提供的文档引用来自不同的Firestore实例。E/AndroidRuntime(26208):at com.google.firebase.firestore.firebaseFirestore.zza(未知来源:17)E/AndroidRuntime(26208):at com.google.firebase.firestore.transaction.get(未知来源:2)E/AndroidRuntime(26208):at io.flutter.plugins.firebase.cloudFirestore.cloudFirestore.cloudFirestore.cloudFirestore.4.doinbackgin(26208):at.java:316)e/androidRuntime(26208):at android.os.asyncTask$2.调用(asynctask.java:333)e/androidRuntime(26208):at java.util.concurrent.futureTask.run(FutureTask.java:266)e/androidRuntime(26208):...4更多d/FlutterNativeView(26208):handlePlatformMessage回复一个分离的视图,channel=plugins.flutter.io/cloud_FireStoreI/FirebaseAuth(26208):[FirebaseAuth:]准备创建到gms实现的服务连接

以下是基于https://github.com/flutter/plugins/tree/master/packages/cloud_firestore#用法的代码

   final DocumentReference postRef =
    Firestore.instance.document('posts/post1');
    Firestore.instance.runTransaction((Transaction tx) async {
      DocumentSnapshot postSnapshot = await tx.get(postRef);
      if (postSnapshot.exists) {
      await tx.update(postRef,
          <String, dynamic>{'likesCt': postSnapshot.data['likesCt'] + 1});
      }
    });

pubspec.lock:

  cloud_firestore:
    dependency: "direct main"
    description:
      name: cloud_firestore
      url: "https://pub.dartlang.org"
    source: hosted
    version: "0.7.0+2"

颤医生:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.3.1, on Microsoft Windows [Version 
10.0.16299.431], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[√] Android Studio (version 3.1)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[√] IntelliJ IDEA Community Edition (version 2018.1)
[√] Connected devices (1 available)

• No issues found!

共有1个答案

琴元凯
2023-03-14

我用inmain.dart启动了我的应用程序:

final FirebaseApp app =
      await FirebaseApp.configure(options: _options(), name: 'testauth');
final Firestore firestore = Firestore(app: app);
  await firestore.settings(timestampsInSnapshotsEnabled: true);

身份验证之后,我直接转到HomesCreen.Dart,它正在使用新的FireStore.Instance...与Main的完全无关。

由:java.lang.IllegalArgumentException引起:提供的文档引用来自不同的Firestore实例。

所以我把线去掉了

final Firestore firestore = Firestore(app: app);
await firestore.settings(timestampsInSnapshotsEnabled: true);

并最终使事务按预期运行。我认为这个想法是不要同时发生多个实例。

 类似资料:
  • 我想有一个月历视图显示所有的日子和事件在每一天。我找到了CalendarView,但它并不真正按我想要的方式显示事件。我一直在研究和检查大量的结果,直到我遇到了一个完整的应用程序,这就是SimpleMobileTools's Simple-Calendar。如果您还不明白我要找的是什么,下面是它们在月度视图日历上显示事件的方式: 不过,他们的应用程序有太多的功能,再加上它是一个完整的应用程序。我想

  • 本文向大家介绍Android事件分发机制(上) ViewGroup的事件分发,包括了Android事件分发机制(上) ViewGroup的事件分发的使用技巧和注意事项,需要的朋友参考一下 综述   Android中的事件分发机制也就是View与ViewGroup的对事件的分发与处理。在ViewGroup的内部包含了许多View,而ViewGroup继承自View,所以ViewGroup本身也是一个

  • 问题内容: 我们正在构建一个使用google maps api的应用程序。 我有MapController和MapView,并使用以下命令启用了内置的缩放控件: 我现在想在用户实际放大地图时得到一个事件,我该如何处理?我找不到能检测到缩放级别变化的此类事件或任何常规事件。 更新资料 mapView.getZoomControls()已弃用。并且文档建议改用mapView.setBuiltInZoo

  • 本节详细介绍了如何在 Android 平台上的实现原生插件代码。在读这篇文章前,请参阅应用程序插件关于插件的结构和共同的 JavaScript 接口的概述。本节展示“回声”插件示例,来实现 Cordova webview 与原生平台的通信交互。该示例也可见 CordovaPlugin.java. 基于 Cordova-Android 的 Android 插件,是 Android 的 WebView