firebase - 没有为“对象”类型定义方法“数据”。尝试将名称更正为现有方法的名称,或定义名为“数据”的方法
问题描述
我在显示来自 Firebase 的数据时遇到问题。这是我在 FutureBuilder 中使用的代码。看起来关于 data() 有一个错误,但我不知道是哪一个,有人知道吗?
这就是我得到的:“方法'data'没有为'Object'类型定义。尝试将名称更正为现有方法的名称,或定义一个名为'data'的方法。”
if(snapshot.connectionState == ConnectionState.done) {
Map<String, dynamic> documentData = snapshot.data!.data() as Map<String, dynamic>;
return ListView(
children: [
CustomSubtitle(
text: "${documentData['01 - Brand']}"
),
CustomTitle(
text: "${documentData['02 - Name']}",
),
CustomText(
text: "${documentData['04 - Description']}",
)
],
);
}
解决方案
如果有人在我的情况下,我找到了解决方案:
builder: (context, AsyncSnapshot<DocumentSnapshot> snapshot) {
if(snapshot.connectionState == ConnectionState.done) {
DocumentSnapshot<Object?> documentData = snapshot.data!;
return ListView(
children: [
CustomSubtitle(
text: "${documentData['01 - Brand']}"
),
CustomTitle(
text: "${documentData['02 - Name']}",
),
CustomText(
text: "${documentData['04 - Description']}",
)
],
);
}
}
推荐阅读
- python - 如何将 xgboost 集成到 spark 中?(Python)
- reactjs - Error shallow Jest Enzyme React cannot find "store"
- straight-line-detection - 如何找到通过最多点的直线?
- node.js - 尝试使用 nodeJS 调用 MongoDB 时未定义获取错误“DB”
- math - 优化函数(例如,电容器充电)曲线的参数以拟合数据
- javascript - iOS Safari Web Audio API 限制问题
- php - API 为不同的参数返回 500 'Internal Server Error'
- c# - .NET Core 子域地址与区域
- java - 如何使用 R2dbc 从 Postgresql 中提取 jsonb 到 Spring webflux
- android - 当我克隆我的 github 项目时,我的项目不工作