Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 方法';[]和#x27;在null&;接收器:空-颤振Android_Flutter_Dart - Fatal编程技术网

Flutter 方法';[]和#x27;在null&;接收器:空-颤振Android

Flutter 方法';[]和#x27;在null&;接收器:空-颤振Android,flutter,dart,Flutter,Dart,widgets库捕获了一个异常,不确定出了什么问题。看来这里的未来建筑商有点问题。那是不是和其他条款一样遗漏了什么?请导游。代码: buildProfileHeader() { return FutureBuilder( future: usersRef.document(widget.profileId).get(), builder: (context, snapshot) { if (!snapshot.hasData) {

widgets库捕获了一个异常,不确定出了什么问题。看来这里的未来建筑商有点问题。那是不是和其他条款一样遗漏了什么?请导游。代码:

buildProfileHeader() {
    return FutureBuilder(
      future: usersRef.document(widget.profileId).get(),
      builder: (context, snapshot) {
        if (!snapshot.hasData) {
          return circularProgress();
        }
        User user = User.fromDocument(snapshot.data);
        return Padding(
          padding: EdgeInsets.all(16.0),
          child: Column(
            children: <Widget>[
              Row(
                children: <Widget>[
                  CircleAvatar(
                    radius: 40.0,
                    backgroundColor: Colors.grey,
                    backgroundImage: CachedNetworkImageProvider(user.photoUrl),
                  ),
                  Expanded(
                    flex: 1,
                    child: Column(
                      children: <Widget>[
                        Row(
                          mainAxisSize: MainAxisSize.max,
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: <Widget>[
                            buildCountColumn("Videos", postCount),
                            buildCountColumn("Followers", 0),
                            buildCountColumn("Following", 0),
                          ],
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: <Widget>[buildProfileButton()],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
              Container(
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(top: 12.0),
                child: Text(
                  user.username,
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 16.0,
                  ),
                ),
              ),
              Container(
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(top: 4.0),
                child: Text(
                  user.displayName,
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ),
              Container(
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.only(top: 2.0),
                child: Text(
                  user.bio,
                ),
              ),
            ],
          ),
        );
      },
    );
  }

从buildProfileButton()函数中可以看出,如果条件为false,它将不会返回任何内容。所以你必须归还一些东西


最后返回空容器可能是最好的解决方案。

添加buildProfileButton()方法和其他方法。@VirenVVarasadiya所有操作都已完成。唯一的问题是在这个buildProfileHeader()中。我想您可能不会从buildProfileButton()方法返回任何东西。我要求的是buildProfileButton()而不是header方法。@VirenVVarasadiya请现在检查。在函数末尾,只需返回容器即可。试一试。始终获取接收器空值错误
buildProfileButton() {
    bool isProfileOwner = currentUserId == widget.profileId;
    if (isProfileOwner) {
      return buildButton(text: "Edit Profile", function: editProfile);
    }
  }