方法' fromsnapshot'为类型定义的IS不定义了病人'飞镖扑来
试图将数据从Firebase加载到数据表 我有一个错误:
未针对“患者”类型定义的方法“ fromsnapshot”。
这是我有这个问题的功能,它显示在“ fromsnapshot”上
Future loadMoreDataFromStream() async {
final stream = collection.snapshots();
stream.listen((snapShot) async {
await Future.forEach(snapShot.docs, (DocumentSnapshot element) {
final Patient data = Patient.fromSnapshot(element);
if (!patients
.any((element) => element.name == data.name)) {
patients.add(data);
addDataGridRow(data);
}
});
updateDataGridDataSource();
});
}
,这是我称之为的类患者
class Patient{
String? name ;
String? pass ;
String? image ;
String? genre ;
DateTime? birth ;
Patient(this.name, this.pass, this.genre,this.birth,{this.reference});
DocumentReference? reference;
static fromSnapshot(DocumentSnapshot snapshot) {
Patient _newPatient = Patient.fromJson(snapshot.data()! as Map<String, dynamic>);
_newPatient.reference = snapshot.reference;
return _newPatient;}
factory Patient.fromJson(Map<String, dynamic> data) =>
Patient(
data['name'],
data['pass'],
data['birth'],
data['genre'],);
Map<String, dynamic> toJson() => _patientToJson(this);
@override
String toString() => 'name $name';
Patient _patientFromJson(Map<String, dynamic> json) {
return Patient(
json['name'],
json['pass'],
json['birth'],
json['genre'],
);}
Map<String, dynamic> _patientToJson(Patient instance) {
return {
'name' : instance.name,
'pass': instance.pass,
'birth': instance.birth,
'genre': instance.genre,
};}}
trying to load data from firebase to a data table
i got this error :
The method 'fromSnapshot' isn't defined for the type 'Patient'.
This is the function where i have this problem , it show on 'fromSnapshot'
Future loadMoreDataFromStream() async {
final stream = collection.snapshots();
stream.listen((snapShot) async {
await Future.forEach(snapShot.docs, (DocumentSnapshot element) {
final Patient data = Patient.fromSnapshot(element);
if (!patients
.any((element) => element.name == data.name)) {
patients.add(data);
addDataGridRow(data);
}
});
updateDataGridDataSource();
});
}
and this is the class Patient that I call
class Patient{
String? name ;
String? pass ;
String? image ;
String? genre ;
DateTime? birth ;
Patient(this.name, this.pass, this.genre,this.birth,{this.reference});
DocumentReference? reference;
static fromSnapshot(DocumentSnapshot snapshot) {
Patient _newPatient = Patient.fromJson(snapshot.data()! as Map<String, dynamic>);
_newPatient.reference = snapshot.reference;
return _newPatient;}
factory Patient.fromJson(Map<String, dynamic> data) =>
Patient(
data['name'],
data['pass'],
data['birth'],
data['genre'],);
Map<String, dynamic> toJson() => _patientToJson(this);
@override
String toString() => 'name $name';
Patient _patientFromJson(Map<String, dynamic> json) {
return Patient(
json['name'],
json['pass'],
json['birth'],
json['genre'],
);}
Map<String, dynamic> _patientToJson(Patient instance) {
return {
'name' : instance.name,
'pass': instance.pass,
'birth': instance.birth,
'genre': instance.genre,
};}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试添加一种方法:
Try adding a method instead:
确保您的班级看起来像这样:
或以下:
Make sure your class looks something like this:
Or this: