0
votes

There is an exception caught by widgets library, not sure whats wrong. Seems kinda issue with the Future builder here. Is that something missing like ELSE clause? Please guide. Code:

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,
                ),
              ),
            ],
          ),
        );
      },
    );
  }

The debug console shows: The method '[]' was called on null. Receiver: null Tried calling: The relevant error-causing widget was FutureBuilder

Even though, the buildProfileButton() is also in place above the buildProfileHeader():

buildProfileButton() {
    bool isProfileOwner = currentUserId == widget.profileId;
    if (isProfileOwner) {
      return buildButton(text: "Edit Profile", function: editProfile);
    }
  }
1
Add buildProfileButton() method and other as well.Viren V Varasadiya
@VirenVVarasadiya All already done. The only issue is in this buildProfileHeader(). specific to future builder.Waseem Khan
I think you may be not returning any thing from buildProfileButton() method. I am asking for buildProfileButton() not header method.Viren V Varasadiya
@VirenVVarasadiya Please check now.Waseem Khan
At the end of function just return container. Give it a try.Viren V Varasadiya

1 Answers

1
votes

As can be seen in your buildProfileButton() function it will not return anything if condition is false. So you have to return something.

Return empty container at the end could be best solution.