首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在执行以下代码时,我报告了以下错误

在执行以下代码时,我报告了以下错误
EN

Stack Overflow用户
提问于 2021-07-26 11:46:05
回答 1查看 56关注 0票数 0

在执行以下代码时,我报告了以下错误

代码语言:javascript
复制
bool isNotEmpty(String text) {
  return text?.isNotEmpty ?? false;
}

bool isEmpty(String text) {
  return text?.isEmpty ?? true;
}

lib/util/string_util.dart:2:10: Warning: null感知操作的操作数‘?’具有不包括null的类型'String‘。返回text?.isNotEmpty ??假;

lib/util/string_util.dart:6:10: Warning: null感知操作的操作数‘?’具有不包括null的类型'String‘。返回text?.isEmpty ??真的;

enter image description here

enter image description here

EN

回答 1

Stack Overflow用户

发布于 2021-07-26 12:26:09

试试这个

代码语言:javascript
复制
  bool isNotEmpty(String? text) {
    if (text == null) {
      text = "";
    }
    return text.isNotEmpty;
  }

  bool isEmpty(String? text) {
    if (text == null) {
      text = "";
    }
    return text.isEmpty;
  }

More detail

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68524281

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档