我正在尝试将数据存储在firebasedatabase
的模型数组中我的firebasedatabase响应如下所示:
{-Ku3EYNaR_E5XVhAij2w: {customerAddress: Ram, customerMobileNumber: 921212121211, CustomerName: Ram, customerImageURL: }, -Ku3F6_0jro_5CI7FDsY: {customerAddress: Qweqweqwe, customerMobileNumber: 888888, CustomerName: Siva, customerImageURL: }}
我的模型看起来像这样
class listOfUsers {
String name = '';
String phoneNumber = '';
String address = '';
listOfUsers(this.name,this.phoneNumber,this.address);
}
List<listOfUsers>userInformation_ = <listOfUsers>[];
getusersinfo() async{
FirebaseUser user = await FirebaseAuth.instance.currentUser();
if (user != null) {
_messagesRef
.child(user.uid)
.child('x')
.onValue
.listen((Event event) {
print('value: ${event.snapshot.value}');
var a = event.snapshot.value;
for(var child in event.snapshot.value){
print(child);
}
});
}
}
getting error as
[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
NoSuchMethodError: Class '_InternalLinkedHashMap' has no instance getter 'iterator'.
Receiver: _LinkedHashMap len:2
任何人都可以帮我将firebase数据库中的数据存储到flutter中的模型
答案 0 :(得分:2)
您可以手动编写序列化方法和反序列化构造函数,从类实例创建JSON /获取JSON并将值分配给实例字段
或者您可以使用其中一个代码生成解决方案来自动生成代码