gpt4 book ai didi

firebase - 类型 '_JsonQuerySnapshot' 不是类型转换中类型 'Map' 的子类型”

转载 作者:行者123 更新时间:2023-12-04 17:17:01 26 4
gpt4 key购买 nike

我在显示来自 Firebase 的数据时遇到问题。这是我在 FutureBuilder 中使用的代码。
这是我得到的错误

"The following _CastError was thrown building FutureBuilder<QuerySnapshot<Object?>>(dirty, state: _FutureBuilderState<QuerySnapshot<Object?>>#c8a1c):
type '_JsonQuerySnapshot' is not a subtype of type 'Map<String, dynamic>' in type cast"
代码
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:errandkaba_app/widgets/custom_action_bar.dart';
import 'package:flutter/material.dart';

class ServicePage extends StatefulWidget {
final String? serviceId;
const ServicePage({Key? key, this.serviceId}) : super(key: key);

@override
_ServicePageState createState() => _ServicePageState();
}

class _ServicePageState extends State<ServicePage> {
final CollectionReference _servicesRef =
FirebaseFirestore.instance.collection("cleaning");



@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
FutureBuilder (
future: _servicesRef.get(),
builder: (context, snapshot){
//if has error
if (snapshot.hasError) {
return Scaffold(
body: Center(
child: Text("Error ${snapshot.error}"),
),
);
}

if(snapshot.connectionState == ConnectionState.done){
Map<String, dynamic> documentData = snapshot.data as Map<String, dynamic>;

return ListView(
children: [
Image.network(
"${documentData['images'][0]}"
),
],
);

}

最佳答案

试试 snapshot.datasnapshot.data!.data()

关于firebase - 类型 '_JsonQuerySnapshot' 不是类型转换中类型 'Map<String, dynamic>' 的子类型”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68494359/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com