Firestore runTransaction永远不会运行 [英] Firestore runTransaction never runs

查看:66
本文介绍了Firestore runTransaction永远不会运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我的代码与酒吧中的示例代码完全一样.如果我只是在没有事务的情况下运行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的最新版本引起了此问题.我最近升级到了主频道中的最新频道,并且开始遇到相同的问题.当我在Stable频道中降级到最新版本时,问题就消失了.

感谢 crushman1报告,并更新了降级对他有用.降级到最新的稳定版本对我也是如此.

降级步骤可以在此处

I am having the strangest problem. One day, out of the blue, runTransaction simply stopped running completely. no errors. no messages. any print statements i put there never runs. nothing. like as if the runTransaction statement is not there at all.

My code is exactly like the example code on the pub. if i just run update or set or add without the transaction it works perfectly.

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});
                  }
                });

No error messages at all. nothing in the catch, nothing in then. The entire thing never runs. its like its being skipped

here is my 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

解决方案

I conclude it is a recent version of Flutter that has caused this issue. I recently upgraded to the latest in the master channel and I started having the same problems. Once I downgraded to latest build in the Stable channel, the problem went away.

Thanks to crushman1 for reporting this and updating that a downgrade worked for him. Downgrading to latest stable build fixed it for me as well.

Steps to downgrade can be found HERE

这篇关于Firestore runTransaction永远不会运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆