我已经做了几个月的Flutter 翼了,我知道如何解决无效的安全问题,但这个问题对我来说真的很复杂,我希望得到帮助.
我的问题是:
每当我try 登录时,我都会收到这样的错误:‘Null’类型不是类型映射、字符串、动态类型的子类型.我尽了最大努力找出哪里出了问题,但我无法, 任何帮助都是拯救生命...
import 'package:cloud_firestore/cloud_firestore.dart';
class User {
final String email;
final String uid;
final String photoUrl;
final String username;
final String bio;
final List followers;
final List following;
const User({
required this.email,
required this.uid,
required this.photoUrl,
required this.username,
required this.bio,
required this.followers,
required this.following,
});
然后我继续在这里
Map<String, dynamic> toJson() => {
"username": username,
"uid": uid,
"email": email,
"photoUrl": photoUrl,
"bio": bio,
"followers": followers,
"following": following,
};
static User fromSnap(DocumentSnapshot snap) {
var snapshot = snap.data() as Map<String, dynamic>;
return User(
username: snapshot['username'],
uid: snapshot['uid'],
email: snapshot['email'],
photoUrl: snapshot['photoUrl'],
bio: snapshot['bio'],
followers: snapshot['followers'],
following: snapshot['following'],
);
}
}
现在我在这一行得到了错误:空类型不是映射<;字符串,动态&>;的子类型
var snapshot = snap.data() as Map<String, dynamic>;
这都是我的问题, 提前谢谢你.