-1

这段代码

  static fromJson(Map<String, dynamic> j) {
    return _TheCountry(
      name: j["Name"]??"",
      dialCode: j["DialCode"]??"",
      iso2Code: j["Iso2"]??"",
      englishName: j["EnglishName"]??"",
      iso3Code: j["Iso3"]??"",
      currency: j["Currency"]??"",
      capital: j["Capital"]??"",
      dialLengths: List.castFrom(getDialLengths(j["DialLength"]??"",)),
    );
  }

以前工作过,但现在测试因抛出而失败,

Failed to load "xxx/xxxx/the_country_number_test.dart": type 'Null' is not a subtype of type 'String'

访问时抛出错误j['DialCode']('DialCode' 属性可能不存在),AFAIK 访问 DialCode 属性j['DialCode']给了我Null对象,但我如何摆脱使用j['DialCode']??""

4

1 回答 1

0

尝试contains像这样使用

j.contains("DialCode") ? j["DialCode"] : “” 
于 2020-12-19T07:11:21.527 回答