gpt4 book ai didi

firebase - Flutter:未处理的异常:错误状态:DocumentSnapshotPlatform中不存在该字段

转载 作者:行者123 更新时间:2023-12-03 15:18:41 24 4
gpt4 key购买 nike

我是新手,我正在通过自定义的教程构建社交媒体应用程序。
现在,我尝试将更多输入字段添加到用户个人资料页面,然后开始出现以下错误。当我可以登录时,我的时间轴页面变成红色,带有警告Bad state: field does not exist within the DocumentSnapshotPlatform我运行了Flutter clean,现在我的用户无法登录该应用程序
我收到此错误:

E/flutter ( 3971): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Bad state: field does not exist within the DocumentSnapshotPlatform
E/flutter ( 3971): #0 DocumentSnapshotPlatform.get._findKeyValueInMap
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:82
E/flutter ( 3971): #1 DocumentSnapshotPlatform.get._findComponent
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:98
E/flutter ( 3971): #2 DocumentSnapshotPlatform.get
package:cloud_firestore_platform_interface/…/platform_interface/platform_interface_document_snapshot.dart:113
E/flutter ( 3971): #3 DocumentSnapshot.get
package:cloud_firestore/src/document_snapshot.dart:49
E/flutter ( 3971): #4 DocumentSnapshot.[]
package:cloud_firestore/src/document_snapshot.dart:56
E/flutter ( 3971): #5 new User.fromDocument
package:findemed/models/user.dart:46
E/flutter ( 3971): #6 _HomeState.createUserInFirestore
package:findemed/pages/home.dart:152
E/flutter ( 3971): <asynchronous suspension>
E/flutter ( 3971): #7 _HomeState.handleSignIn
package:findemed/pages/home.dart:60
E/flutter ( 3971): #8 _HomeState.initState.<anonymous closure>
package:findemed/pages/home.dart:46
E/flutter ( 3971): #9 _rootRunUnary (dart:async/zone.dart:1198:47)

最初是指向我主文件的此dart部分
buildUsersToFollow() {
return StreamBuilder(
stream: usersRef.orderBy('timestamp', descending: true)
.limit(0)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return circularProgress(context);
}
List<UserResult> userResults = [];
snapshot.data.docs.forEach((doc) {
User user = User.fromDocument(doc);
final bool isAuthUser = currentUser.id == user.id;
final bool isFollowingUser = followingList.contains(user.id);
// remove auth user from recommended list
if (isAuthUser) {
return;
} else if (isFollowingUser) {
return;
} else {
UserResult userResult = UserResult(user);
userResults.add(userResult);
}
});


现在,它指向此代码段:
factory User.fromDocument(DocumentSnapshot doc) {
return User(
id: doc['id'],
email: doc['email'],
username: doc['username'],
photoUrl: doc['photoUrl'],
displayName: doc['displayName'],
bio: doc['bio'],
fullNames: doc['fullNames'],
practice: doc['practice'],
speciality: doc['speciality'],
phone: doc['phone'],
mobile: doc['mobile'],
emergency: doc['emergency'],
address: doc['address'],
city: doc['city'],
location: doc['location'],
);
}
这是堆栈中指出的另一部分代码
currentUser = User.fromDocument(doc);
print(currentUser);
print(currentUser.username);

最佳答案

Change your factory to this:-
factory User.fromDocument(DocumentSnapshot doc) {
return User(
id: doc.data()['id'],
email: doc.data()['email'],
username: doc.data()['username'],
photoUrl: doc.data()['photoUrl'],
displayName: doc.data()['displayName'],
bio: doc.data()['bio'],
fullNames: doc.data()['fullNames'],
practice: doc.data()['practice'],
speciality: doc.data()['speciality'],
phone: doc.data()['phone'],
mobile: doc.data()['mobile'],
emergency: doc.data()['emergency'],
address: doc.data()['address'],
city: doc.data()['city'],
location: doc.data()['location'],
);
}

关于firebase - Flutter:未处理的异常:错误状态:DocumentSnapshotPlatform中不存在该字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64949640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com