Android 方法';[]和#x27;在null上调用了。颤振

Android 方法';[]和#x27;在null上调用了。颤振,android,flutter,flutter-futurebuilder,Android,Flutter,Flutter Futurebuilder,我的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"],
    );
  }

这可能是因为您从查询中接收空值。 您想将documentSnapshot[“postId”]映射到您的帖子,但此事件因null而失败

对于干净的代码,我建议您使用 并用json映射您的帖子。 然后检查value==null:

factory Score.fromJson(Map<String, dynamic> json) => Score(
    score: json["score"] == null ? null : json["score"].toDouble(),
factory Score.fromJson(映射json)=>Score(
score:json[“score”]==null?null:json[“score”].toDouble(),

添加Post类
factory Score.fromJson(Map<String, dynamic> json) => Score(
    score: json["score"] == null ? null : json["score"].toDouble(),