新增:键入"_InternalLinkedHashMap<字符串,动态>"不是'DocumentSnapshot'类型的子类型 [英] New: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'DocumentSnapshot'
本文介绍了新增:键入"_InternalLinkedHashMap<字符串,动态>"不是'DocumentSnapshot'类型的子类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对不起,我现在正在编程中,但是我正在学习中,请帮助我.我被困在这个问题上.这是我的第一个应用程序,在需要帮助的情况下,所有事情都要做得到.
Sorry I am now in programming, but I an learning do please help me. I am stuck at this issue. This is one of my first app, and allmost done so need at likke help to get it done.
我收到此错误:类型'_InternalLinkedHashMap'不是类型'DocumentSnapshot'的子类型
I am getting this error: type '_InternalLinkedHashMap' is not a subtype of type '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
这篇关于新增:键入"_InternalLinkedHashMap<字符串,动态>"不是'DocumentSnapshot'类型的子类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文