【问题标题】:The getter 'isNotEmpty' was called on null. Receiver: null Tried calling: isNotEmpty在 null 上调用了 getter 'isNotEmpty'。接收方:null 尝试调用:isNotEmpty
【发布时间】:2023-03-20 01:53:01
【问题描述】:
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(),
            ],
          ),
        );
      }

【问题讨论】:

    标签: flutter dart


    【解决方案1】:
    profileData.photoUrl.isNotEmpty
    

    需要

    profileData?.photoUrl?.isNotEmpty ?? false
    

    因此,如果未设置 profileDataprofileData.photoUrl,它将默认为 false

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      • 2021-09-13
      • 2021-03-06
      • 2021-06-25
      • 1970-01-01
      • 2020-11-01
      • 1970-01-01
      相关资源
      最近更新 更多