在 null 上调用了 getter 'isNotEmpty'。接收者:空尝试调用:isNotEmpty

时间:2021-05-07 12:08:10

标签: flutter dart

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 个答案:

答案 0 :(得分:3)

profileData.photoUrl.isNotEmpty

必须

profileData?.photoUrl?.isNotEmpty ?? false

因此,如果未设置 falseprofileData,它将默认为 profileData.photoUrl