我的 futurebuilder 发生错误高于任何人有任何解决方案相关的导致错误的小部件是:FutureBuilder .................... ..................................................... ..................................................... ..................................................... ..................................................... ...................................................... ............
noti.dart
Widget build(BuildContext context) {
return FutureBuilder(
future: postReference
.document(userId)
.collection("usersPosts")
.document(postId)
.get(),
builder: (context, datasnapshot) {
if (!datasnapshot.hasData) {
return circularProgress();
}
Post post = Post.fromDocument(datasnapshot.data);
return Center(
child: Scaffold(
appBar: header(context, strTitle: post.description),
body: ListView(
children: <Widget>[
Container(
child: post,
),
],
),
),
);
});
Post.dart
class Post extends StatefulWidget {
final String postId;
final String ownerId;
// final String timestamp;
final dynamic likes;
final String username;
final String description;
final String location;
final String url;
//
Post({
this.postId,
this.ownerId,
// this.timestamp,
this.likes,
this.username,
this.description,
this.location,
this.url,
});
factory Post.fromDocument(DocumentSnapshot documentSnapshot) {
return Post(
postId: documentSnapshot["postId"],
ownerId: documentSnapshot["ownerId"],
likes: documentSnapshot["likes"],
// timestamp: documentSnapshot["timestamp"],
username: documentSnapshot["username"],
description: documentSnapshot["description"],
location: documentSnapshot["location"],
url: documentSnapshot["url"],
);
}
引用它的 post 方法:
displayPost(context) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PostScreen(
postId: postId,
userId: userId,
),
),
);
}