【发布时间】:2020-05-27 10:17:26
【问题描述】:
我正在尝试使用 Flutter 和 Firestore 构建应用程序,但我对必须将数据从 Firestore 实现到 Dart 语言的方式感到困惑,所以问题是我的 Firestore 中有一个地图数组,数组中的每个元素都代表一个这样的地图
在我的应用程序中,我想将 Firestore 中的数据表示为可读的东西,我声明了一个这样的类:
class rest_model{
String rest_name;
GeoPoint rest_lat_long;
GeoPoint city_lat_long;
var rest_address = new Map();
var rest_food_list = new List<Map>();
我知道如何将其他转换为变量或可读,我使用这种方法:
rest_model.map(dynamic obj){
this.rest_name = obj['rest_name'];
this.rest_lat_long = obj['rest_lat_long'];
this.city_lat_long = obj['city_lat_long'];
this.rest_address['rest_email'] = obj['rest_address']['rest_email'];
this.rest_address['rest_phone']=obj['rest_address']['rest_phone'];
this.rest_address['rest_website'] = obj['rest_address']['rest_website'];
}
rest_model.fromMap(Map<String, dynamic> map){
this.rest_name = map['rest_name'];
this.rest_lat_long = map['rest_lat_long'];
this.city_lat_long = map['city_lat_long'];
this.rest_address['rest_email'] = map['rest_address']['rest_email'];
this.rest_address['rest_phone']=map['rest_address']['rest_phone'];
this.rest_address['rest_website'] = map['rest_address']['rest_website'];
}
Map<String, dynamic> toMap(){
var map = new Map<String, dynamic>();
map['rest_name'] = rest_name ;
map['rest_lat_long'] = rest_lat_long;
map['city_lat_long'] = city_lat_long;
map['rest_address'] = rest_address.values;
}
但是我不知道如何转换地图rest_food_list的数组。
请任何人都可以帮助我?
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore