首页 > 解决方案 > 在 null 上调用了 getter 'isNotEmpty'。接收方:null 尝试调用:isNotEmpty

问题描述

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

标签: flutterdart

解决方案


profileData.photoUrl.isNotEmpty

需要是

profileData?.photoUrl?.isNotEmpty ?? false

所以它将默认为falseifprofileDataprofileData.photoUrlnot 设置。


推荐阅读