【问题标题】:Type 'String' is not a subtype of type 'List<String>'“String”类型不是“List<String>”类型的子类型
【发布时间】:2020-12-04 06:24:23
【问题描述】:

如果widget.tagname 列表中存在标签,我有以下代码可以正常工作。

List<String> split = widget.tagname?.split(',')??'';

但是,如果列表中没有标签,我会收到此错误;

type 'String' is not a subtype of type 'List<String>'

我做错了什么?

【问题讨论】:

    标签: string list flutter dart split


    【解决方案1】:

    如果tagnamenull,则编译器会尝试将值'' 分配给List&lt;String&gt;,这是不可能的。将'' 替换为[] 就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 2021-07-06
      • 2021-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多