gpt4 book ai didi

firebase - 新增: '_InternalLinkedHashMap'类型不是 'DocumentSnapshot'类型的子类型

转载 作者:行者123 更新时间:2023-12-03 03:38:23 27 4
gpt4 key购买 nike

抱歉,我现在正在编程中,但是我正在学习中,请帮助我。我被困在这个问题上。这是我的第一个应用程序,在likke帮助下需要完成所有工作。

我收到此错误:类型'_InternalLinkedHashMap'不是类型'DocumentSnapshot'的子类型

代码如下:

    import 'package:flutter/material.dart';
import 'package:brew_app/services/auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

class Home extends StatelessWidget {

final AuthService _auth = AuthService();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor : Colors.grey[50],
appBar: AppBar(
title: Text('Brew Crew'),
backgroundColor: Colors.orange[400],
elevation: 0.0,
actions: <Widget>[
FlatButton.icon(
icon: Icon(Icons.person),
label: Text('Logout'),
onPressed:() async {
await _auth.signOut();

},

)
],
),
body: ListPage(),
);
}

}
  class ListPage extends StatefulWidget {



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

class _ListPageState extends State<ListPage> {

Future getPosts() async {
var firestore = Firestore.instance;

QuerySnapshot qn = await firestore.collection("posts").getDocuments();

return qn.documents;


}

navigateToDetails(DocumentSnapshot post){
Navigator.push(context, MaterialPageRoute(builder: (context) => DetailPage(post: post,)));
}

@override
Widget build(BuildContext context) {
return Container(
child: FutureBuilder(
future: getPosts(),
builder: (_, snapshot){
if(snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: Text("Loading..."),
);
} else {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (_, index){

return ListTile(
title: Text(snapshot.data[index].data["title"]),
onTap: () => navigateToDetails(snapshot.data[index].data),
);

});


}

}),
);

}
}
class DetailPage extends StatefulWidget {


final DocumentSnapshot post;

DetailPage({this.post});
@override
_DetailPageState createState() => _DetailPageState();
}

class _DetailPageState extends State<DetailPage> {
@override
Widget build(BuildContext context) {
return Container(
child: Card(
child: ListTile(
title: Text(widget.post.data["title"]),
subtitle: Text(widget.post.data["content"]),
)
)
);
}
}

最佳答案

使用此代码:

snapshot.data[index].data // is of type Map<String,Dynamic>     
snapshot.data[index] // is the DocumentSnapshot

关于firebase - 新增: '_InternalLinkedHashMap<String, dynamic>'类型不是 'DocumentSnapshot'类型的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59130622/

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