Firebase 带颤振的Firestore后中心地图
我正试图使用flifter将整个地图发布到Firestore,如下所示:Firebase 带颤振的Firestore后中心地图,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,我正试图使用flifter将整个地图发布到Firestore,如下所示: Profile { String studentFirstName; String studentSurname; String yearLevel; String preferredHand; Map<String, dynamic> background = {}; Profile({ this.studentFirstName, this.studentSurname,
Profile {
String studentFirstName;
String studentSurname;
String yearLevel;
String preferredHand;
Map<String, dynamic> background = {};
Profile({
this.studentFirstName,
this.studentSurname,
this.yearLevel,
this.preferredHand,
this.background,
)}
Future<bool> createStudent(String schoolId) async {
var newStudent = await db
.collection('schoolStudents')
.doc(schoolId)
.collection('students')
.add({
'studentFirstName': _profile.studentFirstName,
'studentSurname': _profile.studentSurname,
'yearLevel': _profile.yearLevel,
'preferredHand': _profile.preferredHand,
'background': {_profile.background},
}
}
Profile{
字符串studentFirstName;
学生姓氏;
字符串级别;
喜欢用红字;
地图背景={};
侧面图({
这个,学生名字,
这个学生姓,
这一级,,
这是我的老手,
这个背景,,
)}
Future createStudent(字符串schoolId)异步{
var newStudent=await db
.collection('学生')
博士(学号)
.collection(‘学生’)
.添加({
“studentFirstName”:_profile.studentFirstName,
“学生姓氏”:,
“yearLevel”:_profile.yearLevel,
“preferredHand”:_profile.preferredHand,
'背景':{u profile.background},
}
}
但是,此操作失败,并显示以下错误消息
未处理的异常:无效参数:“\u CompactLinkedHashSet”的实例
有没有人能告诉我你是否可以将整个地图发布到Firestore,如果没有,请告诉我最合适的方式。正如你所说,
“有人能告诉我您是否可以将整个地图发布到Firestore,如果没有,请告诉我最合适的方式。”
所以试着用这种方式发布数据(示例)
Map-Map=Map();
map={“name”:“abc”,“id”:“1”};
Future createStudent(字符串schoolId)异步{
var newStudent=await db.collection('schoolstudens').doc(schoolId)
.collection(‘学生’)
.添加({
“studentFirstName”:_profile.studentFirstName,
“学生姓氏”:,
“yearLevel”:_profile.yearLevel,
“preferredHand”:_profile.preferredHand,
“背景”:地图,
}
正如你所说,
“有人能告诉我您是否可以将整个地图发布到Firestore,如果没有,请告诉我最合适的方式。”
所以试着用这种方式发布数据(示例)
Map-Map=Map();
map={“name”:“abc”,“id”:“1”};
Future createStudent(字符串schoolId)异步{
var newStudent=await db.collection('schoolstudens').doc(schoolId)
.collection(‘学生’)
.添加({
“studentFirstName”:_profile.studentFirstName,
“学生姓氏”:,
“yearLevel”:_profile.yearLevel,
“preferredHand”:_profile.preferredHand,
“背景”:地图,
}
问题是您想在Firestore中添加为背景
字段的对象是嵌套的。这是因为配置文件
对象的背景
字段从一开始就已经是一个映射,所以添加括号({}
)在它周围的add
方法中创建Set
的Map
对象,而Set不在其中。这就是错误的原因
因此,似乎从add
方法中删除括号({}
)就足够了:
Future<bool> createStudent(String schoolId) async {
var newStudent = await db
.collection('schoolStudents')
.doc(schoolId)
.collection('students')
.add({
'studentFirstName': _profile.studentFirstName,
'studentSurname': _profile.studentSurname,
'yearLevel': _profile.yearLevel,
'preferredHand': _profile.preferredHand,
'background': _profile.background,
})
Future createStudent(字符串schoolId)异步{
var newStudent=await db
.collection('学生')
博士(学号)
.collection(‘学生’)
.添加({
“studentFirstName”:_profile.studentFirstName,
“学生姓氏”:,
“yearLevel”:_profile.yearLevel,
“preferredHand”:_profile.preferredHand,
“背景”:_profile.background,
})
问题是您想在Firestore中添加为背景
字段的对象是嵌套的。这是因为配置文件
对象的背景
字段从一开始就已经是一个映射,所以添加括号({}
)在它周围的add
方法中创建Set
的Map
对象,而Set不在其中。这就是错误的原因
因此,似乎从add
方法中删除括号({}
)就足够了:
Future<bool> createStudent(String schoolId) async {
var newStudent = await db
.collection('schoolStudents')
.doc(schoolId)
.collection('students')
.add({
'studentFirstName': _profile.studentFirstName,
'studentSurname': _profile.studentSurname,
'yearLevel': _profile.yearLevel,
'preferredHand': _profile.preferredHand,
'background': _profile.background,
})
Future createStudent(字符串schoolId)异步{
var newStudent=await db
.collection('学生')
博士(学号)
.collection(‘学生’)
.添加({
“studentFirstName”:_profile.studentFirstName,
“学生姓氏”:,
“yearLevel”:_profile.yearLevel,
“preferredHand”:_profile.preferredHand,
“背景”:_profile.background,
})