【问题标题】:Firestore runTransaction never runsFirestore runTransaction 永远不会运行
【发布时间】:2019-10-10 13:52:37
【问题描述】:

我遇到了最奇怪的问题。有一天,runTransaction 出乎意料地完全停止了运行。没有错误。没有消息。我放在那里的任何打印语句都不会运行。没有。就像 runTransaction 语句根本不存在一样。

我的代码与 pub 上的示例代码完全相同。如果我只运行 updatesetadd 而没有事务,它会完美运行。

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

根本没有错误消息。 catch 中没有任何内容,then 中没有任何内容。整个事情永远不会运行。就像被跳过了

这是我的 pubspeck.yaml :

dependencies:
  flutter:
    sdk: flutter
  http: ^0.12.0
  font_awesome_flutter: ^8.2.0
  fluttertoast: ^3.0.4
  datetime_picker_formfield: ^0.1.7
  flutter_image_compress: ^0.4.0
  cloud_firestore: ^0.11.0+2
  firebase_auth: ^0.11.1
  google_sign_in: ^4.0.1+3
  firebase_messaging: ^4.0.0+3
  shared_preferences: ^0.5.2
  firebase_storage: ^3.0.0
  flutter_rating: ^0.0.2
  flutter_typeahead: ^1.4.0
  url_launcher: ^4.0.3
  flutter_facebook_login: ^2.0.0
  algolia: ^0.1.5
  geolocator: ^4.0.3
  provider: ^2.0.1

【问题讨论】:

    标签: flutter google-cloud-firestore


    【解决方案1】:

    我断定是最近版本的 Flutter 导致了这个问题。我最近升级到主频道的最新版本,我开始遇到同样的问题。一旦我降级到稳定频道中的最新版本,问题就消失了。

    感谢crushman1 for reporting 这并更新降级对他有用。降级到最新的稳定版本也为我修复了它。

    降级步骤见HERE

    【讨论】:

    • 这似乎已通过 Cloud Firestore 0.12.2 修复。
    • 确认使用目前使用 Flutter 1.5.4+2 Dart 2.3.0 的稳定通道再次工作。在 cloud_firestore 0.12.5+2 中链接
    猜你喜欢
    • 2021-08-05
    • 1970-01-01
    • 2015-05-31
    • 1970-01-01
    • 2021-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-06
    相关资源
    最近更新 更多