Ad

Type 'String' Is Not A Subtype Of Type 'List'

- 1 answer

I've got the following code which works well if there are tags present in the widget.tagname list.

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

However, if there are no tags in the list I get this error;

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

What am I doing wrong?

Ad

Answer

If tagname is null, then the compiler attempts to assign the value '' to a List<String>, which is not possible. Replace '' with [] and you should be fine.

Ad
source: stackoverflow.com
Ad