【发布时间】:2021-08-06 10:10:28
【问题描述】:
我想访问文档字段,为此我使用以下代码,但出现错误:-
The operator '[]' isn't defined for the type 'Object'. (Documentation)
我的 Cloud Firestore 版本是 cloud_firestore: ^2.1.0
我的代码:-
import 'package:cloud_firestore/cloud_firestore.dart';
class TeamModel
{
final String id;
final String name;
final String url;
final String category;
final String role;
TeamModel({
this.id,
this.name,
this.url,
this.category,
this.role
});
factory TeamModel.fromDocument(DocumentSnapshot doc)
{
return TeamModel(
id: doc.id,
name: doc.data()['name'],// I am getting the error on this ['name']
url: doc.data()['url'], // same error here
category: doc.data()['category'],// same error here
role: doc.data()['role'],// same error here
);
}
}
【问题讨论】:
标签: firebase flutter google-cloud-firestore