【发布时间】:2021-01-19 10:00:06
【问题描述】:
我的 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,
),
),
);
}
【问题讨论】:
-
添加 Post 类
标签: android flutter flutter-futurebuilder