首页 > 解决方案 > 异常:错误状态:DocumentSnapshotPlatform Flutter Firebase 中不存在字段

问题描述

当我尝试启动我的应用程序时,它会引发错误,我正在为我的数据库使用 cloud firestore。我创建了一个自定义类对象,它应该返回存储在我的 firestore 数据库中的数据库。

The string : 'coffee'
The document Id : 'id'

Collection : name
"new crew member"
srength
100
sugars
"0"

异常:错误状态:调试控制台片段中的 DocumentSnapshotPlatform中不存在字段

Launching lib\main.dart on AOSP on IA Emulator in debug mode...
√  Built build\app\outputs\flutter-apk\app-debug.apk.
D/EGL_emulation(10524): eglMakeCurrent: 0xe3b05780: ver 2 0 (tinfo 0xcbb977f0)
I/OpenGLRenderer(10524): Davey! duration=1640ms; Flags=1, IntendedVsync=21923234495143, Vsync=21924734495083, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=21924742691640, AnimationStart=21924742737640, PerformTraversalsStart=21924743916740, DrawStart=21924756908640, SyncQueued=21924762235840, SyncStart=21924765266540, IssueDrawCommandsStart=21924765562940, SwapBuffers=21924776192940, FrameCompleted=21924877730440, DequeueBufferDuration=27493000, QueueBufferDuration=464000,
Connecting to VM Service at ws://127.0.0.1:51346/EM9iZekSWt8=/ws
D/EGL_emulation(10524): eglMakeCurrent: 0xe0eb0140: ver 2 0 (tinfo 0xcbb97100)
D/eglCodecCommon(10524): setVertexArrayObject: set vao to 0 (0) 1 0
W/DynamiteModule(10524): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(10524): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(10524): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/sloo.coffee_da(10524): Unknown chunk type '200'.
I/sloo.coffee_da(10524): The ClassLoaderContext is a special shared library.
I/sloo.coffee_da(10524): The ClassLoaderContext is a special shared library.
I/sloo.coffee_da(10524): The ClassLoaderContext is a special shared library.
W/sloo.coffee_da(10524): Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
V/NativeCrypto(10524): Registering com/google/android/gms/org/conscrypt/NativeCrypto's 294 native methods...
W/sloo.coffee_da(10524): Accessing hidden method Ljava/security/spec/ECParameterSpec;->getCurveName()Ljava/lang/String; (light greylist, reflection)
I/ProviderInstaller(10524): Installed default security provider GmsCore_OpenSSL

════════ Exception caught by provider ══════════════════════════════════════════
The following assertion was thrown:
An exception was throw by _MapStream<QuerySnapshot<Map<String, dynamic>>, List<Coffee>> listened by

StreamProvider<List<Coffee>?>, but no `catchError` was provided.

Exception:
Bad state: field does not exist within the DocumentSnapshotPlatform

════════════════════════════════════════════════════════════════════════════════
W/sloo.coffee_da(10524): Accessing hidden field Ljava/net/Socket;->impl:Ljava/net/SocketImpl; (light greylist, reflection)
W/sloo.coffee_da(10524): Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, linking)
W/sloo.coffee_da(10524): Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, linking)
W/sloo.coffee_da(10524): Accessing hidden field Ljava/io/FileDescriptor;->descriptor:I (light greylist, JNI)
W/sloo.coffee_da(10524): Accessing hidden method Ljava/security/spec/ECParameterSpec;->setCurveName(Ljava/lang/String;)V (light greylist, reflection)
W/sloo.coffee_da(10524): Accessing hidden method Ldalvik/system/BlockGuard;->getThreadPolicy()Ldalvik/system/BlockGuard$Policy; (light greylist, linking)
W/sloo.coffee_da(10524): Accessing hidden method Ldalvik/system/BlockGuard$Policy;->onNetwork()V (light greylist, linking)

database.dart 文件如下所示:

class DatabaseService {
  final String uid;
  DatabaseService({required this.uid});

  final CollectionReference<Map<String, dynamic>> coffeeCollection =
      FirebaseFirestore.instance.collection('coffee');

  Future updateUserData(String sugars, String name, int strength) async {
    return await coffeeCollection.doc(uid).set({
      'sugars': sugars,
      'name': name,
      'srength': strength,
    });
  }

  List<Coffee> _coffeeListFromSnapshot(
      QuerySnapshot<Map<String, dynamic>> snapshot) {
    return snapshot.docs.map((doc) {
      return Coffee(
          name: doc.get('name') ?? '',
          strength: doc.get('strength') ?? 0,
          sugars: doc.get('sugars') ?? '0');
    }).toList();
  }

  Stream<List<Coffee>> get coffee {
    return coffeeCollection.snapshots().map(_coffeeListFromSnapshot);
  }
}

标签: androidfirebasefluttergoogle-cloud-firestoremobile

解决方案


推荐阅读