【发布时间】:2021-11-22 07:57:36
【问题描述】:
我有这个代码块,我想用它来从 firebase 数据库中检索数据。但是我对代码有疑问,因为它会带来如下错误消息。我需要帮助来解决这个问题。 错误信息
getter '(' 没有为类型 'UsersData' 定义。 尝试导入定义 '(' 的库,将名称更正为现有 getter 的名称,或定义 get
代码
void _getPhoneNos(BuildContext context) async {
fb.Database db = fb.database();
fb.DatabaseReference<ReferenceJsImpl> dataRef = db.ref('users');
dataRef.onValue.listen((event) {
fb.DataSnapshot snapshot = event.snapshot;
if (snapshot == null) {
print("Result is Empty");
return;
}
List<UsersData>usersInfo= snapshot.val();
usersInfo.forEach((Item) {
_singleTextFieldcontroller.text = Item.Item("phone");
});
});
这是用户数据。
class UsersData {
String id;
String name;
String type;
String phone;
String residential;
UsersData({
this.id,
this.name,
this.type,
this.phone,
this.residential,
});
UsersData.fromJson(this.id, Map data) {
name = data['name'];
type = data['type'];
phone = data['phone'];
residential = data['residential'];
}
}
【问题讨论】: