我正在将 Flutter 用于移动应用程序,并且最近注意到一个间歇性错误,导致从 Cloud Firestore 读取文档失败。我终于得到了我的一台设备来获取错误,因此我将其插入以获取日志,当我尝试访问其中一个文档时出现此错误。
flutter : [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] 未处理的异常:PlatformException(执行获取时出错,由于客户端离线,无法获取文档。,空)
这个错误是从我的这行代码中抛出的,它在 99.9% 的时间内适用于 99.9% 的用户
DocumentSnapshot userLivestream = await Firestore.instance.collection('livestreams').document(userId).get();
Run Code Online (Sandbox Code Playgroud)
我已经阅读了很多关于该主题的内容,并得到了很多不同的答案。一个堆栈溢出帖子说它是在 2.5 年前修复的(显然不是,参考:Firebase Cloud Firestore 抛出“客户端离线”),其他人说它是特定于 android 的(参考:https : //github.com/EddyVerbruggen/nativescript -plugin-firebase/issues/631),但我在 android 和 iOS 上都遇到了同样的问题。这个问题最近变得更糟了,所以可能是我使用的包的问题。这里的相关包是从我的 pubspec.yaml 粘贴过来的。
firebase_core: ^0.4.0+1
cloud_firestore: ^0.11.0+1
firebase_auth: ^0.11.1
Run Code Online (Sandbox Code Playgroud)
有时错误会在一段时间后自行修复,它可能与登录应用程序或更改设备连接的网络有关,但有了这些信息,我仍然无法始终如一地复制问题。有没有人遇到过类似的问题,你是如何解决的?
堆栈跟踪:
03-31 13:20:09.488 19623 6084 E flutter : [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(Error performing get, Failed to get document because the client is offline., null)
03-31 13:20:09.488 19623 6084 E flutter : #0 …Run Code Online (Sandbox Code Playgroud) firebase firebase-authentication flutter google-cloud-firestore
我今天已经升级了我所有的 firebase 软件包,我不得不升级到版本 8.0.0-dev.13 以进行 firebase 消息传递,即使由于依赖性问题它仍在开发中。在 Application.Java 中,我有:
package com.halloglobal.flutterapp.hallo;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
import io.flutter.view.FlutterMain;
public class Application extends FlutterApplication implements PluginRegistrantCallback {
@override
public void onCreate() {
super.onCreate();
FlutterFirebaseMessagingService.setPluginRegistrant(this);
}
@override
public void registerWith(PluginRegistry registry) {
FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
}
}
Run Code Online (Sandbox Code Playgroud)
过去运行良好,但现在使用这个新版本,我收到此错误:注意:使用 -Xlint:deprecation 重新编译以获取详细信息。/Users/hallo/Documents/HalloMonoRepo/hallo/android/app/src/main/java/com/halloglobal/flutterapp/hallo/Application.java:7: 错误:包 io.flutter.plugins.firebasemessaging 不存在 import io .flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService; ^ /Users/hallo/Documents/HalloMonoRepo/hallo/android/app/src/main/java/com/halloglobal/flutterapp/hallo/Application.java:8: 错误:包 io.flutter.plugins.firebasemessaging 不存在导入io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
我需要如何更改我的 Application.java 才能使用新版本?