I've got a comma-separated string of tags, IE "grubs, sheep, dog". How can I separate this into three variables? I tried ;
var splitag = tagname.split(",");
var splitag1 = splitag[0];
var splitag2 = splitag[1];
var splitag3 = splitag[2];
But if any of the variables are null it throws an error. So I tried;
String splitagone = splitag1 ?? "";
String splitagtwo = splitag2 ?? "";
String splitagthree = splitag3 ?? "";
But I got the same error. So is there another way I can check that the tag is not null and use the variable?
if(tagname != null) {
tagname.split(',').forEach((tag) {
// something?
});
}