![](/img/trans.png)
[英]Cannot get a Cloud Function to fetch data from Google Cloud IoT Pub/Sub topic and store it in a Firestore Database
[英]Cannot get list of data from cloud firestore
我想从云 Firestore 中获取数据列表。 我已经设置了一切。 使用以下代码,我只能获取一个数据而不是所有列表。 我收到以下错误:错误 state:DocumentSnapshotPlatform 中不存在字段
class HomePage extends StatefulWidget {
static const routeName = 'homePage';
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
late String id;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Latest"),
backgroundColor: Colors.black,
),
body: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection("latest").orderBy('number',descending: true).snapshots(),
builder: (context, snapshot) {
return !snapshot.hasData
? Center(child: CircularProgressIndicator())
: ListView.builder(
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) {
DocumentSnapshot data = snapshot.data!.docs[index];
return Stack(
alignment: Alignment.topCenter,
fit: StackFit.loose,
clipBehavior: Clip.hardEdge,
children: [
GestureDetector(
child: Container(
height: 200,
width: MediaQuery.of(context).size.width,
child: Card(
child: Center(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text(
data['name'],
textAlign: TextAlign.start,
style: const TextStyle(
color: Colors.indigo,
fontWeight: FontWeight.bold,
),
),
])),
)),
onTap: () {
},
)
],
// ),
);
},
);
},
),
);
}
}
我认为您应该检查文档字段名称,并确保所有文档中都存在所有字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.