我在使用flutter将数据保存在firestore数据库中时遇到问题,我有这两个类:
class Level {
final String name;
final List<Materia> materie;
Level({
this.name,
this.materie,
});
Map toJson() {
return {"name": name, "materie": materie};
}
}
class Materia extends Taggable {
final String name;
Materia({
this.name,
});
@override
List<Object> get props => [name];
}
我想将其保存在 firestore 的 MAP 中,但收到此错误:
Unhandled Exception: Invalid argument: Instance of 'Level'
这是我用来保存数据的代码:
Future<bool> saveProfile({String uid, String name, String surname, String address, List<Level> level}) async {
try {
Firestore.instance.collection('users').document(uid).updateData({ 'name': name, 'surname': surname, 'address': address, 'level': level.toJson() });
return true;
} catch (e) {
// throw the Firebase AuthException that we caught
throw new Exception(e.toString());
}
}
谢谢!!