The getter 'isNotEmpty' was called on null. Receiver: null Tried calling: isNotEmpty

Viewed 103
Widget _profileInfo(Users profileData) {
        return Padding(
          padding: const EdgeInsets.all(15.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  CircleAvatar(
                    backgroundColor: Colors.grey,
                    radius: 50.0,
                    backgroundImage: profileData.photoUrl.isNotEmpty 
                        ? NetworkImage(profileData.photoUrl)
                        : AssetImage("images/user.png"),
                  )
                ],
              ),
              SizedBox(
                height: 10.0,
              ),
              Text(
                profileData.userName,
                style: TextStyle(fontSize: 15.0, fontWeight: FontWeight.bold),
              ),
              SizedBox(
                height: 10.0,
              ),
              _profileEditButton(),
              SizedBox(
                height: 10.0,
              ),
              _logoutButton(),
            ],
          ),
        );
      }
1 Answers
profileData.photoUrl.isNotEmpty

needs to be

profileData?.photoUrl?.isNotEmpty ?? false

so it will default to false if profileData or profileData.photoUrl are not set.

Related